package com.github.semres.gui;

import com.github.semres.babelnet.BabelNetManager;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class EditApiKeyController extends ChildController implements Initializable {
    public TextField apiKeyTF;
    public Button editButton;
    public Button cancelButton;
    public Button okButton;

    private BooleanProperty editing = new SimpleBooleanProperty(false);
    private MainController mainController;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        okButton.visibleProperty().bind(editing);
        okButton.managedProperty().bind(okButton.visibleProperty());
        cancelButton.visibleProperty().bind(editing);
        cancelButton.managedProperty().bind(cancelButton.visibleProperty());
        editButton.visibleProperty().bind(editing.not());
        editButton.managedProperty().bind(editButton.visibleProperty());

        apiKeyTF.editableProperty().bind(editing);
        Platform.runLater(() -> apiKeyTF.getParent().requestFocus());
    }

    public void startEditing() {
        editing.set(true);
    }

    public void cancelEditing() {
        editing.set(false);
        apiKeyTF.setText(BabelNetManager.getApiKey());
    }

    public void save() throws IOException {
        mainController.setBabelNetApiKey(apiKeyTF.getText() != null ? apiKeyTF.getText() : "");
        Utils.showInfo("Changes will be applied after the next program launch.");
        Stage stage = (Stage) apiKeyTF.getScene().getWindow();
        stage.close();
    }

    @Override
    public void setParent(Controller parent) {
        mainController = (MainController) parent;
        if (mainController.getNewApiKey() == null) {
            apiKeyTF.setText(BabelNetManager.getApiKey());
        } else {
            apiKeyTF.setText(mainController.getNewApiKey());
        }
    }
}

@@ -202,32 +202,57 @@
 ooleanProperty;%0A
+import javafx.fxml.FXML;%0A
 import javafx.fx
@@ -544,22 +544,29 @@
 e %7B%0A    
-public
+@FXML private
  TextFie
@@ -578,30 +578,37 @@
 iKeyTF;%0A    
-public
+@FXML private
  Button edit
@@ -611,38 +611,45 @@
 editButton;%0A    
-public
+@FXML private
  Button cancelBu
@@ -658,22 +658,29 @@
 on;%0A    
-public
+@FXML private
  Button 

Change controller fields visibility to private, for consistency with rest of the code base.