package controller;

import java.io.File;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Slider;
import javafx.scene.layout.Pane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;


public class UserInterface {
    private MainController myMainController;
    private Pane rootPane;
    private Stage myStage;

    public UserInterface (Stage s, MainController mainController) {
        myMainController = mainController;
        Stage myStage = s;
        myStage.setTitle("Cell Society Team 4");

        rootPane = new Pane();
        Scene myScene = new Scene(rootPane, 500, 540);
        myStage.setScene(myScene);
        myStage.show();
        rootPane.getChildren().add(createAndHandleSlider());
        createAndHandleButtons();
    }

    private Slider createAndHandleSlider () {
        Slider slider = new Slider(0, 1, 0.1);
        slider.setLayoutX(320);
        slider.setLayoutY(515);
        slider.valueProperty().addListener(new ChangeListener<Number>() {
            public void changed (ObservableValue<? extends Number> ov,
                                 Number old_val, Number new_val) {
                myMainController.setSimulationSpeed((double) new_val);
            }
        });
        return slider;
    }

    private void createAndHandleButtons () {
        rootPane.getChildren().add(createButton("Start", 0, 510, new EventHandler<ActionEvent>() {
            @Override
            public void handle (ActionEvent event) {
                myMainController.startSimulation();
            }
        }));
        rootPane.getChildren().add(createButton("Stop", 60, 510, new EventHandler<ActionEvent>() {
            @Override
            public void handle (ActionEvent event) {
                myMainController.stopSimulation();
            }
        }));
        rootPane.getChildren().add(createButton("Step", 120, 510, new EventHandler<ActionEvent>() {
            @Override
            public void handle (ActionEvent event) {
                myMainController.stepSimulation();
            }
        }));
        rootPane.getChildren().add(createButton("Choose File", 200, 510, new EventHandler<ActionEvent>() {
            @Override
            public void handle (ActionEvent event) {
                // show file dialog
                FileChooser fileChooser = new FileChooser();
                fileChooser.setTitle("Open XML File");
                final File XMLData = fileChooser.showOpenDialog(myStage);
                myMainController.initializeSimulationWithData(XMLData);
            }
        }));
    }

    private Button createButton (String title, int posX, int posY, EventHandler<ActionEvent> handler) {
        Button button = new Button(title);
        button.setLayoutX(posX);
        button.setLayoutY(posY);
        button.setOnAction(handler);
        return button;
    }

    public Pane getRootPane () {
        return rootPane;
    }
}

@@ -855,642 +855,89 @@
     
-rootPane.getChildren().add(createAndHandleSlider());%0A        createAndHandleButtons();%0A    %7D%0A%0A    private Slider createAndHandleSlider () %7B%0A        Slider slider = new Slider(0, 1, 0.1);%0A        slider.setLayoutX(320);%0A        slider.setLayoutY(515);%0A        slider.valueProperty().addListener(new ChangeListener%3CNumber%3E() %7B%0A            public void changed (ObservableValue%3C? extends Number%3E ov,%0A                                 Number old_val, Number new_val) %7B%0A                myMainController.setSimulationSpeed((double) new_val);%0A            %7D%0A        %7D);%0A        return slider;%0A    %7D%0A%0A    private void createAndHandleB
+makeBottomPanel();%0A    %7D%0A%0A    private void makeBottomPanel () %7B%0A        //b
 uttons
- () %7B
 %0A   
@@ -2206,282 +2206,967 @@
     
-%7D%0A%0A    private Button createButton (String title, int posX, int posY, EventHandler%3CActionEvent%3E handler) %7B%0A        Button button = new Button(title);%0A        button.setLayoutX(posX);%0A        button.setLayoutY(posY);%0A        button.setOnAction(handler);%0A        return button
+    //slider%0A        rootPane.getChildren().add(createSlider(0,1,.1,320,515, new ChangeListener%3CNumber%3E()%7B%0A            public void changed (ObservableValue%3C? extends Number%3E ov,%0A                                 Number old_val, Number new_val) %7B%0A                myMainController.setSimulationSpeed((double) new_val);%0A            %7D%0A        %7D));%0A    %7D%0A%0A    private Button createButton (String title, int posX, int posY, EventHandler%3CActionEvent%3E handler) %7B%0A        Button button = new Button(title);%0A        button.setLayoutX(posX);%0A        button.setLayoutY(posY);%0A        button.setOnAction(handler);%0A        return button;%0A    %7D%0A    %0A    private Slider createSlider (int start, int stop, double startVal, int posX, int posY, ChangeListener%3CNumber%3E listener)%7B%0A        Slider slider = new Slider(start, stop, startVal);%0A        slider.setLayoutX(posX);%0A        slider.setLayoutY(posY);%0A        slider.valueProperty().addListener(listener);%0A        return slider
 ;%0A  

Make slider generation more concise