Example usage for javafx.scene.control TextArea getParent

List of usage examples for javafx.scene.control TextArea getParent

Introduction

In this page you can find the example usage for javafx.scene.control TextArea getParent.

Prototype

public final Parent getParent() 

Source Link

Usage

From source file:sudoku.controller.ViewController.java

public void attachTextEventHandlers(ArrayList<TextArea> textAreas) {
    for (TextArea textArea : textAreas) {
        textArea.textProperty().addListener((final ObservableValue<? extends String> observable,
                final String oldValue, final String newValue) -> {
            String parentID = textArea.getParent().getId();
            //get the row and column of the cell
            int row = parentID.charAt(0) - 48;
            int column = parentID.charAt(1) - 48;

            System.out.println("Parent: " + textArea.getParent().getId());
            //if it's an empty cell
            if (newValue.equals(""))
                GameController.userBoard[row][column] = 0;

            // if the length is greater than 1, it's an invalid input
            if (newValue.length() > 1)
                textArea.setText(oldValue);
            //make sure that the user is actually providing a +ve number greater than 0 as an input
            if (newValue.length() > 0) {
                int value = newValue.charAt(0) - 48;
                if (!Character.isDigit(newValue.charAt(0)) || newValue.charAt(0) == 48) {
                    textArea.setText("");
                    GameController.userBoard[row][column] = 0;
                } else {
                    //for an illegal move, set the cell's text to a red color
                    if (!solver.isLegal(GameController.userBoard, row, column, value)) {
                        textArea.setStyle("-fx-text-fill: red;");
                    } else {
                        textArea.setStyle("-fx-text-fill: black;");
                    }/*from  w w  w .j  av a  2 s.  c  o m*/
                    GameController.userBoard[row][column] = value;
                }
            }
        });
    }
}