package org.mystic.kagan;

import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.Group;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;


public class Controller {

    private static final String TRAINING_SESSION_PATH = "/compare/training-session";
    private static final String MAIN_SESSION_PATH = "/compare/main-session";
    @FXML
    Group rootGroup;
    @FXML
    Button startTestButton;
    @FXML
    TextArea instructionText;

    @FXML
    private void closeWindow() {
        System.out.println(rootGroup.getChildren().size());
        System.exit(0);
    }

    private final double[] x = {294, 14, 190, 366, 537, 14, 190, 366, 537};
    private final double[] y = {25, 185, 185, 185, 185, 367, 367, 367, 367};

    @FXML
    private void startKaganTest() {
        startTestButton.setDisable(true);
        instructionText.setVisible(false);
        for (int i = 0; i <= 8; ++i) {
            final String url = Controller.class.getResource(TRAINING_SESSION_PATH + "/1/" + i + ".jpg").toString();
            ImageView imageView = new ImageView(new Image(url));
            imageView.setLayoutX(x[i]);
            imageView.setLayoutY(y[i]);
            imageView.setFitWidth(200);
            imageView.setFitHeight(150);
            imageView.setPreserveRatio(true);
            imageView.setPickOnBounds(true);
            imageView.setOnMouseClicked(new EventHandler<MouseEvent>() {
                @Override
                public void handle(MouseEvent mouseEvent) {
                    final double sceneX = mouseEvent.getSceneX();
                    final double sceneY = mouseEvent.getSceneY();
                    for (int j = 1; j <= 8; ++j) {
                        if (sceneX >= x[j] && sceneX <= x[j] + 200 && sceneY >= y[j] && sceneY <= y[j] + 150) {
                            System.out.println("Clicked on figure number" + j);
                        }
                    }
                }
            });
            rootGroup.getChildren().add(imageView);
        }
    }
}
@@ -300,16 +300,71 @@
 ent;%0D%0A%0D%0A
+import java.util.ArrayList;%0D%0Aimport java.util.List;%0D%0A%0D%0A
 %0D%0Apublic
@@ -546,24 +546,179 @@
 -session%22;%0D%0A
+    private final double%5B%5D x = %7B294, 14, 190, 366, 537, 14, 190, 366, 537%7D;%0D%0A    private final double%5B%5D y = %7B25, 185, 185, 185, 185, 367, 367, 367, 367%7D;%0D%0A
     @FXML%0D%0A 
@@ -886,241 +886,23 @@
 tem.
-out.println(rootGroup.getChildren().size());%0D%0A        System.exit(0);%0D%0A    %7D%0D%0A%0D%0A    private final double%5B%5D x = %7B294, 14, 190, 366, 537, 14, 190, 366, 537%7D;%0D%0A    private final double%5B%5D y = %7B25, 185, 185, 185, 185, 367, 367, 367, 367%7D;
+exit(0);%0D%0A    %7D
 %0D%0A%0D%0A
@@ -945,24 +945,58 @@
 anTest() %7B%0D%0A
+        final int%5B%5D steps = %7B1%7D;%0D%0A
         star
@@ -1066,24 +1066,280 @@
 le(false);%0D%0A
+        final List%3CImageView%3E images = new ArrayList%3CImageView%3E(9);%0D%0A        goNextStep(steps, images);%0D%0A    %7D%0D%0A%0D%0A    private void goNextStep(final int%5B%5D steps, final List%3CImageView%3E images) %7B%0D%0A        if (steps%5B0%5D %3E 14) %7B%0D%0A            return;%0D%0A        %7D%0D%0A
         for 
@@ -1378,29 +1378,79 @@
         
-final 
 String 
+url;%0D%0A            if (steps%5B0%5D %3C= 2) %7B%0D%0A                
 url = Co
@@ -1502,17 +1502,32 @@
 ATH + %22/
-1
+%22 + steps%5B0%5D + %22
 /%22 + i +
@@ -1544,24 +1544,186 @@
 oString();%0D%0A
+            %7D else %7B%0D%0A                url = Controller.class.getResource(MAIN_SESSION_PATH + %22/%22 + (steps%5B0%5D - 2) + %22/%22 + i + %22.jpg%22).toString();%0D%0A            %7D%0D%0A
             
@@ -2491,24 +2491,65 @@
 %5D + 150) %7B%0D%0A
+                            steps%5B0%5D++;%0D%0A
             
@@ -2608,16 +2608,17 @@
 e number
+ 
 %22 + j);%0D
@@ -2614,24 +2614,282 @@
 er %22 + j);%0D%0A
+                            for (ImageView i : images) %7B%0D%0A                                rootGroup.getChildren().remove(i);%0D%0A                            %7D%0D%0A                            images.clear();%0D%0A                            goNextStep(steps, images);%0D%0A
             
@@ -2958,24 +2958,60 @@
        %7D);%0D%0A
+            images.add(imageView);%0D%0A
             

add multiple cases