<commit_before>package client;

import common.Message;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class ChatClient extends Application {
    ObjectOutputStream toServer;
    ObjectInputStream fromServer;

    TextField username;
    TextField address;
    TextField port;

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("ChatClient ### Connection configuration");
        Label addressLabel = new Label("Server IP: ");
        address = new TextField("127.0.0.1");
        HBox addressInput = new HBox(5, addressLabel, address);

        Label portLabel = new Label("Port: ");
        port = new NumericTextField("8000");

        HBox portInput = new HBox(5, portLabel, port);

        Button proceedButton = new Button("OK");
        VBox serverInput = new VBox(10, addressInput, portInput, proceedButton);
        serverInput.setAlignment(Pos.CENTER);
        serverInput.setPadding(new Insets(10, 10, 10, 10));

        primaryStage.setScene(new Scene(serverInput));

        Label usernameLabel = new Label("Username: ");
        username = new TextField();

        HBox usernameInput = new HBox(usernameLabel, username);
        Button usernameButton = new Button("OK");
        HBox userInput = new HBox(usernameLabel, usernameInput, usernameButton);

        username.setOnAction(e -> primaryStage.setScene(new Scene(userInput)));
        port.setOnAction(e -> primaryStage.setScene(new Scene(userInput)));
        proceedButton.setOnAction(e -> primaryStage.setScene(new Scene(userInput)));

        usernameButton.setOnAction(e -> openChat(primaryStage));
        username.setOnAction(e -> openChat(primaryStage));

        primaryStage.setOnCloseRequest(e -> System.exit(0));
        primaryStage.show();
    }

    private void openChat(Stage primaryStage) {

            String name = username.getText().trim();


            BorderPane paneForTextField = new BorderPane();
            paneForTextField.setPadding(new Insets(5, 5, 5, 5));
            paneForTextField.setStyle("-fx-border-color: green");
            paneForTextField.setLeft(new Label("Input message: "));

            TextField textField = new TextField();
            textField.setAlignment(Pos.BOTTOM_LEFT);
            paneForTextField.setCenter(textField);

            BorderPane mainPane = new BorderPane();
            TextArea textArea = new TextArea();
            mainPane.setCenter(new ScrollPane(textArea));
            mainPane.setTop(paneForTextField);
            textArea.setEditable(false);

            Scene scene = new Scene(mainPane, 1350, 600);
            primaryStage.setTitle(address.getText() + ":" + port.getText() + "### ChatClient ### " + name);
            primaryStage.setScene(scene);

            textField.setOnAction(e -> {
                try {

                    String text = textField.getText().trim();
                    Message msg = new Message(name, text);<commit_msg>Refactored chat client configuration scenes<commit_after>package client;

import common.Message;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class ChatClient extends Application {
    ObjectOutputStream toServer;
    ObjectInputStream fromServer;

    TextField username;
    TextField address;
    TextField port;

    Stage primary;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        this.primary = primaryStage;

        Scene userScene = createUserConfigScene();
        prepareHostConfigScene(userScene);

        primary.setOnCloseRequest(e -> System.exit(0));
        primary.show();
    }

    private Scene createUserConfigScene() {
        HBox usernameInputBox = createUsernameInputBox();

        Button proceedButton = new Button("OK");
        proceedButton.setOnAction(e -> openChat());

        HBox userInput = new HBox(usernameInputBox, proceedButton);
        return new Scene(userInput);
    }

    private HBox createUsernameInputBox() {
        Label usernameLabel = new Label("Username: ");
        username = new TextField();
        username.setOnAction(e -> openChat());
        return new HBox(usernameLabel, username);
    }

    private void prepareHostConfigScene(Scene nextScene) {
        primary.setTitle("ChatClient ### Connection configuration");

        HBox addressInput = createAddressBox(nextScene);
        HBox portInput = createPortBox(nextScene);
        Button proceedButton = crerateButtonNext(nextScene);

        Scene serverScene = createServerScene(addressInput, portInput, proceedButton);
        primary.setScene(serverScene);
    }

    private Scene createServerScene(HBox addressInput, HBox portInput, Button proceedButton) {
        VBox serverInput = new VBox(10, addressInput, portInput, proceedButton);
        serverInput.setAlignment(Pos.CENTER);
        serverInput.setPadding(new Insets(10, 10, 10, 10));
        return new Scene(serverInput);
    }

    private Button crerateButtonNext(Scene nextScene) {
        Button proceedButton = new Button("OK");
        proceedButton.setOnAction(e -> primary.setScene(nextScene));
        return proceedButton;
    }

    private HBox createPortBox(Scene nextScene) {
        Label portLabel = new Label("Port: ");
        port = new NumericTextField("8000");
        port.setOnAction(e -> primary.setScene(nextScene));
        return new HBox(5, portLabel, port);
    }

    private HBox createAddressBox(Scene nextScene) {
        Label addressLabel = new Label("Server IP: ");
        address = new TextField("127.0.0.1");
        address.setOnAction(e -> primary.setScene(nextScene));
        return new HBox(5, addressLabel, address);
    }

    private void openChat() {

            String name = username.getText().trim();

            BorderPane paneForTextField = new BorderPane();
            paneForTextField.setPadding(new Insets(5, 5, 5, 5));
            paneForTextField.setLeft(new Label("Input message: "));

            TextField textField = new TextField();
            textField.setAlignment(Pos.BOTTOM_LEFT);
            paneForTextField.setCenter(textField);

            BorderPane mainPane = new BorderPane();
            TextArea textArea = new TextArea();
            mainPane.setCenter(new ScrollPane(textArea));
            mainPane.setTop(paneForTextField);
            textArea.setEditable(false);

            Scene scene = new Scene(mainPane, 1350, 600);
            primary.setTitle(address.getText() + ":" + port.getText() + "### ChatClient ### " + name);
            primary.setScene(scene);

            textField.setOnAction(e -> {
                try {

                    String text = textField.getText().trim();
                    Message msg = new Message(name, text);
{'fraction_non_alphanumeric': 0.10506145103739924, 'fraction_numerical': 0.008986388264834149, 'mean_word_length': 2.964379256155055, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4091202', 'n_tokens_mistral': 2094, 'n_tokens_neox': 1970, 'n_words': 459}