package harmony.mastermind.ui;

import javafx.scene.Node;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Popup;

//@@author A0139149X
public class HelpPopup extends UiPart {

    private static final String FXML = "HelpPopup.fxml";
    private Popup popup;
    private TextArea content;
    private boolean isFirstKey;

    //@@author A0139149X
    public HelpPopup() {
        initPopup();
        isFirstKey = true;
    }

    //@@author A0139149X
    public void show(Node node) {
        popup.show(node, 200, 100);
        popup.centerOnScreen();
    }

    //@@author A0139149X
    @Override
    public void setNode(Node node) {
    }

    //@@author A0139149X
    @Override
    public String getFxmlPath() {
        return FXML;
    }
    
    //@@author A0139149X
    @FXML
    private void initPopup() {
        popup = new Popup();
        content = new TextArea();
        content.setPrefHeight(575);
        content.setPrefWidth(700);

        popup.getContent().add(content);
        popup.addEventHandler(KeyEvent.KEY_RELEASED, keyEventHandler);

        content.setEditable(false);
    }

    //@@author A0139149X
    @FXML
    EventHandler<KeyEvent> keyEventHandler = new EventHandler<KeyEvent>() {
        public void handle(KeyEvent event) {
            if (!isFirstKey && event.getCode() != null) {
                popup.hide();
            }
            isFirstKey = !isFirstKey;
        }
    };

    //@@author A0139149X
    public void setContent(String text) {
        content.setText(text);
    }
}

@@ -430,18 +430,18 @@
 r A01391
-4
 9
+4
 X%0Apublic
@@ -633,34 +633,34 @@
 /@@author A01391
-4
 9
+4
 X%0A    public Hel
@@ -738,34 +738,34 @@
 /@@author A01391
-4
 9
+4
 X%0A    public voi
@@ -872,34 +872,34 @@
 /@@author A01391
-4
 9
+4
 X%0A    @Override%0A
@@ -959,26 +959,26 @@
 uthor A01391
-4
 9
+4
 X%0A    @Overr
@@ -1060,34 +1060,34 @@
 /@@author A01391
-4
 9
+4
 X%0A    @FXML%0A    
@@ -1421,26 +1421,26 @@
 uthor A01391
-4
 9
+4
 X%0A    @FXML%0A
@@ -1743,10 +1743,10 @@
 1391
-4
 9
+4
 X%0A  

type wrong metric