package edu.utah.sci.cyclist.core.ui.wizards;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.Window;
import edu.utah.sci.cyclist.Cyclist;

public class SaveWsWizard extends VBox {
	
	// GUI elements
	private Stage                 _dialog;
	private ObjectProperty<Boolean> _selection = new SimpleObjectProperty<>();
	// * * * Constructor creates a new stage * * * //
	public SaveWsWizard() {	
		createDialog();
	}

	// * * * Show the dialog * * * //
	public ObjectProperty<Boolean> show(Window window) {
		_dialog.initOwner	(window);
		_dialog.show();
		_dialog.setX(window.getX() + (window.getWidth() - _dialog.getWidth())*0.5);
		_dialog.setY(window.getY() + (window.getHeight() - _dialog.getHeight())*0.5);
		return _selection;
	}
		
	// * * * Create the dialog
	private void createDialog(){	

		_dialog = new Stage();
		_dialog.setTitle("Save WorkSpace");
		_dialog.setHeight(100);
		
		
		_dialog.initModality(Modality.WINDOW_MODAL);
		_dialog.setScene( createScene(_dialog) );
	}

		// * * * Create scene creates the GUI * * * //
		private Scene createScene(final Stage dialog) {

			VBox vbox = new VBox();
			vbox.setSpacing(10);
			vbox.setAlignment(Pos.CENTER);
			
			Text text = new Text("WorkSpace has been modified. Save changed? ");  
			text.setFont(new Font(12));
			
			HBox hbox = new HBox();
			hbox.setAlignment(Pos.BOTTOM_CENTER);
			hbox.setSpacing(10);
			hbox.setPadding(new Insets(5));
			hbox.setMinWidth(300);
			
			Button yes = new Button("Yes");
			yes.setMinWidth(50);
			yes.setAlignment(Pos.CENTER);
			Button no = new Button("No");
			no.setMinWidth(50);
			no.setAlignment(Pos.CENTER);
			Button cancel = new Button("Cancel");
			cancel.setMinWidth(50);
			cancel.setAlignment(Pos.CENTER);
			hbox.getChildren().addAll(yes,no,cancel);
			cancel.setOnAction(new EventHandler<ActionEvent>() {
				@Override
				public void handle(ActionEvent arg0) {
					_dialog.hide();
				};
			});
			yes.setOnAction(new EventHandler<ActionEvent>() {
				@Override
				public void handle(ActionEvent arg0) {
					_selection.set(true);
					_dialog.hide();
				};
			});
			no.setOnAction(new EventHandler<ActionEvent>() {
				@Override
				public void handle(ActionEvent arg0) {
					_selection.set(false);
					_dialog.hide();
				};
			});
			
			vbox.getChildren().addAll(text,hbox);
			
			// Create the scene
			Scene scene = new Scene(vbox);
			
			scene.getStylesheets().add(Cyclist.class.getResource("assets/Cyclist.css").toExternalForm());
			return scene;
		}	
}
@@ -325,16 +325,51 @@
 Button;%0A
+import javafx.scene.input.KeyCode;%0A
 import j
@@ -389,24 +389,24 @@
 ayout.HBox;%0A
-
 import javaf
@@ -1672,25 +1672,25 @@
 w Text(%22Work
-S
+s
 pace has bee
@@ -1948,16 +1948,49 @@
 %22Yes%22);%0A
+//%09%09%09yes.setDefaultButton(true);%0A
 %09%09%09yes.s
@@ -2167,16 +2167,49 @@
 ncel%22);%0A
+%09%09%09cancel.setCancelButton(true);%0A
 %09%09%09cance
@@ -2456,16 +2456,111 @@
 %0A%09%09%09%7D);%0A
+%09%09%09cancel.setOnKeyPressed((ke)-%3E %7B if (ke.getCode() == KeyCode.ENTER) %7B cancel.fire(); %7D %7D );%0A%0A
 %09%09%09yes.s
@@ -2723,16 +2723,103 @@
 %0A%09%09%09%7D);%0A
+%09%09%09yes.setOnKeyPressed((ke)-%3E %7Bif (ke.getCode() == KeyCode.ENTER) yes.fire(); %7D );%0A%09%09%09%0A
 %09%09%09no.se
@@ -2975,23 +2975,105 @@
 %0A%09%09%09%09%7D;%0A
-
 %09%09%09%7D);%0A
+%09%09%09no.setOnKeyPressed((ke)-%3E %7B if (ke.getCode() == KeyCode.ENTER) no.fire(); %7D );%0A
 %09%09%09%0A%09%09%09v

enable escape/return keys on the save exit panel