2017-11-11 22:27:19 +01:00
/ * *
* cemu_UI
*
2018-04-28 12:17:12 +02:00
* Copyright 2017 - 2018 < @Seil0 >
2017-11-11 22:27:19 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston ,
* MA 02110 - 1301 , USA .
* /
2017-11-13 16:44:39 +01:00
package com.cemu_UI.uiElements ;
2017-11-11 22:27:19 +01:00
2017-12-19 21:35:49 +01:00
import java.util.ResourceBundle ;
2017-11-11 22:27:19 +01:00
import com.jfoenix.controls.JFXButton ;
import com.jfoenix.controls.JFXDialog ;
import com.jfoenix.controls.JFXDialogLayout ;
import javafx.event.ActionEvent ;
import javafx.event.EventHandler ;
import javafx.scene.layout.AnchorPane ;
import javafx.scene.layout.Pane ;
import javafx.scene.layout.StackPane ;
import javafx.scene.text.Text ;
public class JFXOkayCancelDialog {
private String headingText ;
private String bodyText ;
private String dialogBtnStyle ;
2017-12-19 21:35:49 +01:00
private String okayText ;
private String cancelText ;
2017-11-11 22:27:19 +01:00
private int dialogWidth ;
private int dialogHeight ;
2017-11-22 23:30:20 +01:00
private EventHandler < ActionEvent > okayAction ;
private EventHandler < ActionEvent > cancelAction ;
2017-11-11 22:27:19 +01:00
private Pane pane ;
/ * *
* Creates a new JFoenix Dialog to show some information with okay and cancel option
* @param headingText Heading Text , just the heading
* @param bodyText body Text , all other text belongs here
* @param dialogBtnStyle Style of the okay button
* @param dialogWidth dialog width
* @param dialogHeight dialog height
* @param okayAction action which is performed if the okay button is clicked
* @param cancelAction action which is performed if the cancel button is clicked
* @param pane pane to which the dialog belongs
* /
public JFXOkayCancelDialog ( String headingText , String bodyText , String dialogBtnStyle , int dialogWidth ,
2017-12-19 21:35:49 +01:00
int dialogHeight , EventHandler < ActionEvent > okayAction , EventHandler < ActionEvent > cancelAction , Pane pane ,
ResourceBundle bundle ) {
2017-11-11 22:27:19 +01:00
this . headingText = headingText ;
this . bodyText = bodyText ;
this . dialogBtnStyle = dialogBtnStyle ;
this . dialogWidth = dialogWidth ;
this . dialogHeight = dialogHeight ;
2017-11-22 23:30:20 +01:00
this . okayAction = okayAction ;
this . cancelAction = cancelAction ;
2017-11-11 22:27:19 +01:00
this . pane = pane ;
2017-12-19 22:18:22 +01:00
okayText = bundle . getString ( " okayBtnText " ) ;
cancelText = bundle . getString ( " cancelBtnText " ) ;
2017-11-11 22:27:19 +01:00
}
public void show ( ) {
2017-12-19 21:35:49 +01:00
2017-11-15 15:58:23 +01:00
JFXDialogLayout content = new JFXDialogLayout ( ) ;
2017-11-11 22:27:19 +01:00
content . setHeading ( new Text ( headingText ) ) ;
content . setBody ( new Text ( bodyText ) ) ;
StackPane stackPane = new StackPane ( ) ;
stackPane . autosize ( ) ;
JFXDialog dialog = new JFXDialog ( stackPane , content , JFXDialog . DialogTransition . LEFT , true ) ;
2017-11-26 11:35:02 +01:00
JFXButton okayBtn = new JFXButton ( okayText ) ;
2017-11-11 22:27:19 +01:00
okayBtn . addEventHandler ( ActionEvent . ACTION , ( e ) - > {
dialog . close ( ) ;
} ) ;
2017-11-26 11:35:02 +01:00
okayBtn . addEventHandler ( ActionEvent . ACTION , okayAction ) ;
2017-11-11 22:27:19 +01:00
okayBtn . setButtonType ( com . jfoenix . controls . JFXButton . ButtonType . RAISED ) ;
okayBtn . setPrefHeight ( 32 ) ;
okayBtn . setStyle ( dialogBtnStyle ) ;
2017-11-26 11:35:02 +01:00
JFXButton cancelBtn = new JFXButton ( cancelText ) ;
2017-11-11 22:27:19 +01:00
cancelBtn . addEventHandler ( ActionEvent . ACTION , ( e ) - > {
dialog . close ( ) ;
} ) ;
2017-11-26 11:35:02 +01:00
cancelBtn . addEventHandler ( ActionEvent . ACTION , cancelAction ) ;
2017-11-11 22:27:19 +01:00
cancelBtn . setButtonType ( com . jfoenix . controls . JFXButton . ButtonType . RAISED ) ;
cancelBtn . setPrefHeight ( 32 ) ;
cancelBtn . setStyle ( dialogBtnStyle ) ;
2017-12-12 19:01:17 +01:00
content . setActions ( cancelBtn , okayBtn ) ;
2017-11-11 22:27:19 +01:00
content . setPrefSize ( dialogWidth , dialogHeight ) ;
pane . getChildren ( ) . add ( stackPane ) ;
AnchorPane . setTopAnchor ( stackPane , ( pane . getHeight ( ) - content . getPrefHeight ( ) ) / 2 ) ;
AnchorPane . setLeftAnchor ( stackPane , ( pane . getWidth ( ) - content . getPrefWidth ( ) ) / 2 ) ;
dialog . show ( ) ;
}
2017-11-26 11:35:02 +01:00
public String getOkayText ( ) {
return okayText ;
}
public void setOkayText ( String okayText ) {
this . okayText = okayText ;
}
public String getCancelText ( ) {
return cancelText ;
}
public void setCancelText ( String cancelText ) {
this . cancelText = cancelText ;
}
2017-11-20 11:32:14 +01:00
public EventHandler < ActionEvent > getOkayAction ( ) {
return okayAction ;
}
public void setOkayAction ( EventHandler < ActionEvent > okayAction ) {
this . okayAction = okayAction ;
}
public EventHandler < ActionEvent > getCancelAction ( ) {
return cancelAction ;
}
public void setCancelAction ( EventHandler < ActionEvent > cancelAction ) {
this . cancelAction = cancelAction ;
}
2017-11-11 22:27:19 +01:00
}