Search in sources :

Example 1 with CUser

use of com.gianlu.pyxreborn.Models.Client.CUser in project PretendYoureXyzzyReborn by devgianlu.

the class MainUI method refreshUsersList.

@FXML
public void refreshUsersList() {
    JsonObject resp;
    try {
        resp = client.sendMessageBlocking(client.createRequest(Operations.LIST_USERS));
    } catch (InterruptedException | PyxException ex) {
        UIClient.notifyException(ex);
        return;
    }
    JsonArray usersArray = resp.getAsJsonArray(Fields.USERS_LIST.toString());
    ObservableList<CUser> users = new ObservableListWrapper<>(Utils.toList(usersArray, CUser.class));
    usersList.setItems(users);
}
Also used : JsonArray(com.google.gson.JsonArray) CUser(com.gianlu.pyxreborn.Models.Client.CUser) ObservableListWrapper(com.sun.javafx.collections.ObservableListWrapper) JsonObject(com.google.gson.JsonObject) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException) FXML(javafx.fxml.FXML)

Example 2 with CUser

use of com.gianlu.pyxreborn.Models.Client.CUser in project PretendYoureXyzzyReborn by devgianlu.

the class RegisterUI method register.

@FXML
public void register() {
    String nickname = this.nickname.getText();
    try {
        Client client = new Client(new URI(address.getText()), nickname, null, admin.isSelected() ? adminCode.getText() : null);
        if (client.connectBlocking()) {
            CUser me;
            try {
                me = new CUser(client.sendMessageBlocking(client.createRequest(Operations.GET_ME)).getAsJsonObject(Fields.USER.toString()));
            } catch (PyxException ex) {
                UIClient.notifyException(ex);
                return;
            }
            stage.close();
            GlobalChatUI.show(client);
            MainUI.show(client, me);
        } else {
            new Alert(Alert.AlertType.ERROR, "Failed connecting! Nickname may be invalid or server may be full.").show();
        }
    } catch (InterruptedException | URISyntaxException ex) {
        UIClient.notifyException(ex);
    }
}
Also used : CUser(com.gianlu.pyxreborn.Models.Client.CUser) Alert(javafx.scene.control.Alert) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException) URISyntaxException(java.net.URISyntaxException) Client(com.gianlu.pyxreborn.client.Client) URI(java.net.URI) FXML(javafx.fxml.FXML)

Aggregations

PyxException (com.gianlu.pyxreborn.Exceptions.PyxException)2 CUser (com.gianlu.pyxreborn.Models.Client.CUser)2 FXML (javafx.fxml.FXML)2 Client (com.gianlu.pyxreborn.client.Client)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ObservableListWrapper (com.sun.javafx.collections.ObservableListWrapper)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Alert (javafx.scene.control.Alert)1