Search in sources :

Example 1 with StringCell

use of com.faforever.client.fx.StringCell in project downlords-faf-client by FAForever.

the class CoopController method initialize.

public void initialize() {
    missionComboBox.setCellFactory(param -> missionListCell());
    missionComboBox.setButtonCell(missionListCell());
    missionComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> setSelectedMission(newValue));
    playButton.disableProperty().bind(titleTextField.textProperty().isEmpty());
    numberOfPlayersComboBox.setButtonCell(numberOfPlayersCell());
    numberOfPlayersComboBox.setCellFactory(param -> numberOfPlayersCell());
    numberOfPlayersComboBox.getSelectionModel().select(2);
    numberOfPlayersComboBox.getSelectionModel().selectedItemProperty().addListener(observable -> loadLeaderboard());
    // TODO don't use API object but bean instead
    rankColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getRanking()));
    rankColumn.setCellFactory(param -> new StringCell<>(String::valueOf));
    playerCountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getPlayerCount()));
    playerCountColumn.setCellFactory(param -> new StringCell<>(String::valueOf));
    playerNamesColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPlayerNames()));
    playerNamesColumn.setCellFactory(param -> new StringCell<>(String::valueOf));
    secondaryObjectivesColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue().isSecondaryObjectives()));
    secondaryObjectivesColumn.setCellFactory(param -> new StringCell<>(aBoolean -> aBoolean ? i18n.get("yes") : i18n.get("no")));
    timeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDuration()));
    timeColumn.setCellFactory(param -> new StringCell<>(timeService::shortDuration));
    replayColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getId()));
    replayColumn.setCellFactory(param -> new NodeTableCell<>((replayId) -> {
        ReplayButtonController button = uiService.loadFxml("theme/play/coop/replay_button.fxml");
        button.setReplayId(replayId);
        button.setOnClickedAction(this::onReplayButtonClicked);
        return button.getRoot();
    }));
    webViewConfigurer.configureWebView(descriptionWebView);
    ObservableList<Game> games = gameService.getGames();
    FilteredList<Game> filteredItems = new FilteredList<>(games);
    filteredItems.setPredicate(OPEN_COOP_GAMES_PREDICATE);
    GamesTableController gamesTableController = uiService.loadFxml("theme/play/games_table.fxml");
    gamesTableController.initializeGameTable(filteredItems);
    Node root = gamesTableController.getRoot();
    populateContainer(root);
    coopService.getMissions().thenAccept(coopMaps -> {
        Platform.runLater(() -> missionComboBox.setItems(observableList(coopMaps)));
        SingleSelectionModel<CoopMission> selectionModel = missionComboBox.getSelectionModel();
        if (selectionModel.isEmpty()) {
            Platform.runLater(selectionModel::selectFirst);
        }
    }).exceptionally(throwable -> {
        notificationService.addPersistentErrorNotification(throwable, "coop.couldNotLoad", throwable.getLocalizedMessage());
        return null;
    });
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) NewGameInfo(com.faforever.client.game.NewGameInfo) Arrays(java.util.Arrays) GameService(com.faforever.client.game.GameService) UiService(com.faforever.client.theme.UiService) COOP(com.faforever.client.game.KnownFeaturedMod.COOP) ListCell(javafx.scene.control.ListCell) ReportingService(com.faforever.client.reporting.ReportingService) FXCollections.observableList(javafx.collections.FXCollections.observableList) TimeService(com.faforever.client.util.TimeService) ComboBox(javafx.scene.control.ComboBox) Duration(java.time.Duration) GameStatus(com.faforever.client.remote.domain.GameStatus) TableView(javafx.scene.control.TableView) Pane(javafx.scene.layout.Pane) TextField(javafx.scene.control.TextField) Predicate(java.util.function.Predicate) SingleSelectionModel(javafx.scene.control.SingleSelectionModel) FilteredList(javafx.collections.transformation.FilteredList) AbstractViewController(com.faforever.client.fx.AbstractViewController) CoopResult(com.faforever.client.api.dto.CoopResult) DismissAction(com.faforever.client.notification.DismissAction) Platform(javafx.application.Platform) Text(javafx.scene.text.Text) ModService(com.faforever.client.mod.ModService) ObservableList(javafx.collections.ObservableList) NodeTableCell(com.faforever.client.fx.NodeTableCell) PreferencesService(com.faforever.client.preferences.PreferencesService) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Scope(org.springframework.context.annotation.Scope) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) Strings(com.google.common.base.Strings) StringListCell(com.faforever.client.fx.StringListCell) PasswordField(javafx.scene.control.PasswordField) ReportAction(com.faforever.client.notification.ReportAction) WebView(javafx.scene.web.WebView) StringCell(com.faforever.client.fx.StringCell) Collections.emptySet(java.util.Collections.emptySet) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Node(javafx.scene.Node) ReplayService(com.faforever.client.replay.ReplayService) WebViewConfigurer(com.faforever.client.fx.WebViewConfigurer) GamesTableController(com.faforever.client.game.GamesTableController) Component(org.springframework.stereotype.Component) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Severity(com.faforever.client.notification.Severity) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ImageView(javafx.scene.image.ImageView) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Game(com.faforever.client.game.Game) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SingleSelectionModel(javafx.scene.control.SingleSelectionModel) Node(javafx.scene.Node) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) GamesTableController(com.faforever.client.game.GamesTableController) FilteredList(javafx.collections.transformation.FilteredList) Game(com.faforever.client.game.Game)

Example 2 with StringCell

use of com.faforever.client.fx.StringCell in project downlords-faf-client by FAForever.

the class LiveReplayController method initializeGameTable.

private void initializeGameTable(ObservableList<Game> games) {
    SortedList<Game> sortedList = new SortedList<>(games);
    sortedList.comparatorProperty().bind(liveReplayControllerRoot.comparatorProperty());
    mapPreviewColumn.setCellFactory(param -> new MapPreviewTableCell(uiService));
    mapPreviewColumn.setCellValueFactory(param -> Bindings.createObjectBinding(() -> mapService.loadPreview(param.getValue().getMapFolderName(), PreviewSize.SMALL), param.getValue().mapFolderNameProperty()));
    gameTitleColumn.setCellValueFactory(param -> param.getValue().titleProperty());
    gameTitleColumn.setCellFactory(param -> new StringCell<>(title -> title));
    playersColumn.setCellValueFactory(param -> param.getValue().numPlayersProperty());
    playersColumn.setCellFactory(param -> new StringCell<>(number -> i18n.number(number.intValue())));
    hostColumn.setCellValueFactory(param -> param.getValue().hostProperty());
    hostColumn.setCellFactory(param -> new StringCell<>(String::toString));
    modsColumn.setCellValueFactory(this::modCell);
    modsColumn.setCellFactory(param -> new StringCell<>(String::toString));
    watchColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue()));
    watchColumn.setCellFactory(param -> new NodeTableCell<>(this::watchReplayButton));
    liveReplayControllerRoot.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> Platform.runLater(() -> selectedGame.set(newValue)));
    liveReplayControllerRoot.setItems(games);
}
Also used : GameService(com.faforever.client.game.GameService) UiService(com.faforever.client.theme.UiService) MapPreviewTableCell(com.faforever.client.game.MapPreviewTableCell) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Bindings(javafx.beans.binding.Bindings) Scope(org.springframework.context.annotation.Scope) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) GameStatus(com.faforever.client.remote.domain.GameStatus) TableView(javafx.scene.control.TableView) SortedList(javafx.collections.transformation.SortedList) StringCell(com.faforever.client.fx.StringCell) ObjectProperty(javafx.beans.property.ObjectProperty) Node(javafx.scene.Node) AbstractViewController(com.faforever.client.fx.AbstractViewController) ObservableMap(javafx.collections.ObservableMap) Collectors(java.util.stream.Collectors) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) Platform(javafx.application.Platform) Component(org.springframework.stereotype.Component) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Entry(java.util.Map.Entry) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) NotNull(org.jetbrains.annotations.NotNull) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Image(javafx.scene.image.Image) Game(com.faforever.client.game.Game) NodeTableCell(com.faforever.client.fx.NodeTableCell) Joiner(com.google.common.base.Joiner) MapPreviewTableCell(com.faforever.client.game.MapPreviewTableCell) Game(com.faforever.client.game.Game) SortedList(javafx.collections.transformation.SortedList)

Example 3 with StringCell

use of com.faforever.client.fx.StringCell in project downlords-faf-client by FAForever.

the class GamesTableController method initializeGameTable.

public void initializeGameTable(ObservableList<Game> games) {
    SortedList<Game> sortedList = new SortedList<>(games);
    sortedList.comparatorProperty().bind(gamesTable.comparatorProperty());
    gamesTable.setPlaceholder(new Label(i18n.get("games.noGamesAvailable")));
    gamesTable.setRowFactory(param1 -> gamesRowFactory());
    gamesTable.setItems(sortedList);
    applyLastSorting(gamesTable);
    gamesTable.setOnSort(this::onColumnSorted);
    sortedList.addListener((Observable observable) -> selectFirstGame());
    selectFirstGame();
    passwordProtectionColumn.setCellValueFactory(param -> param.getValue().passwordProtectedProperty());
    passwordProtectionColumn.setCellFactory(param -> passwordIndicatorColumn());
    mapPreviewColumn.setCellFactory(param -> new MapPreviewTableCell(uiService));
    mapPreviewColumn.setCellValueFactory(param -> Bindings.createObjectBinding(() -> mapService.loadPreview(param.getValue().getMapFolderName(), PreviewSize.SMALL), param.getValue().mapFolderNameProperty()));
    gameTitleColumn.setCellValueFactory(param -> param.getValue().titleProperty());
    gameTitleColumn.setCellFactory(param -> new StringCell<>(title -> title));
    playersColumn.setCellValueFactory(param -> Bindings.createObjectBinding(() -> new PlayerFill(param.getValue().getNumPlayers(), param.getValue().getMaxPlayers()), param.getValue().numPlayersProperty(), param.getValue().maxPlayersProperty()));
    playersColumn.setCellFactory(param -> playersCell());
    ratingColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(new RatingRange(param.getValue().getMinRating(), param.getValue().getMaxRating())));
    ratingColumn.setCellFactory(param -> ratingTableCell());
    hostColumn.setCellValueFactory(param -> param.getValue().hostProperty());
    hostColumn.setCellFactory(param -> new StringCell<>(String::toString));
    modsColumn.setCellValueFactory(this::modCell);
    modsColumn.setCellFactory(param -> new StringCell<>(String::toString));
    gamesTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> Platform.runLater(() -> selectedGame.set(newValue)));
}
Also used : PreferencesService(com.faforever.client.preferences.PreferencesService) Pos(javafx.geometry.Pos) UiService(com.faforever.client.theme.UiService) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) HashMap(java.util.HashMap) Bindings(javafx.beans.binding.Bindings) Scope(org.springframework.context.annotation.Scope) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) Map(java.util.Map) TableView(javafx.scene.control.TableView) SortedList(javafx.collections.transformation.SortedList) StringCell(com.faforever.client.fx.StringCell) ObjectProperty(javafx.beans.property.ObjectProperty) Pair(javafx.util.Pair) Label(javafx.scene.control.Label) Controller(com.faforever.client.fx.Controller) Node(javafx.scene.Node) TableRow(javafx.scene.control.TableRow) Observable(javafx.beans.Observable) Collectors(java.util.stream.Collectors) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) Platform(javafx.application.Platform) SortType(javafx.scene.control.TableColumn.SortType) Component(org.springframework.stereotype.Component) List(java.util.List) SortEvent(javafx.scene.control.SortEvent) RatingRange(com.faforever.client.remote.domain.RatingRange) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Entry(java.util.Map.Entry) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) NotNull(org.jetbrains.annotations.NotNull) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Image(javafx.scene.image.Image) Joiner(com.google.common.base.Joiner) RatingRange(com.faforever.client.remote.domain.RatingRange) SortedList(javafx.collections.transformation.SortedList) Label(javafx.scene.control.Label) Observable(javafx.beans.Observable)

Example 4 with StringCell

use of com.faforever.client.fx.StringCell in project downlords-faf-client by FAForever.

the class LeaderboardController method initialize.

@Override
public void initialize() {
    super.initialize();
    rankColumn.setCellValueFactory(param -> param.getValue().rankProperty());
    rankColumn.setCellFactory(param -> new StringCell<>(rank -> i18n.number(rank.intValue())));
    nameColumn.setCellValueFactory(param -> param.getValue().usernameProperty());
    nameColumn.setCellFactory(param -> new StringCell<>(name -> name));
    winLossColumn.setCellValueFactory(param -> new SimpleFloatProperty(param.getValue().getWinLossRatio()));
    winLossColumn.setCellFactory(param -> new StringCell<>(number -> i18n.get("percentage", number.floatValue() * 100)));
    gamesPlayedColumn.setCellValueFactory(param -> param.getValue().gamesPlayedProperty());
    gamesPlayedColumn.setCellFactory(param -> new StringCell<>(count -> i18n.number(count.intValue())));
    ratingColumn.setCellValueFactory(param -> param.getValue().ratingProperty());
    ratingColumn.setCellFactory(param -> new StringCell<>(rating -> i18n.number(rating.intValue())));
    contentPane.managedProperty().bind(contentPane.visibleProperty());
    connectionProgressPane.managedProperty().bind(connectionProgressPane.visibleProperty());
    connectionProgressPane.visibleProperty().bind(contentPane.visibleProperty().not());
    searchTextField.textProperty().addListener((observable, oldValue, newValue) -> {
        if (Validator.isInt(newValue)) {
            ratingTable.scrollTo(Integer.parseInt(newValue) - 1);
        } else {
            LeaderboardEntry foundPlayer = null;
            for (LeaderboardEntry leaderboardEntry : ratingTable.getItems()) {
                if (leaderboardEntry.getUsername().toLowerCase().startsWith(newValue.toLowerCase())) {
                    foundPlayer = leaderboardEntry;
                    break;
                }
            }
            if (foundPlayer == null) {
                for (LeaderboardEntry leaderboardEntry : ratingTable.getItems()) {
                    if (leaderboardEntry.getUsername().toLowerCase().contains(newValue.toLowerCase())) {
                        foundPlayer = leaderboardEntry;
                        break;
                    }
                }
            }
            if (foundPlayer != null) {
                ratingTable.scrollTo(foundPlayer);
                ratingTable.getSelectionModel().select(foundPlayer);
            } else {
                ratingTable.getSelectionModel().select(null);
            }
        }
    });
}
Also used : Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) ReportingService(com.faforever.client.reporting.ReportingService) Scope(org.springframework.context.annotation.Scope) TableColumn(javafx.scene.control.TableColumn) NavigateEvent(com.faforever.client.main.event.NavigateEvent) Inject(javax.inject.Inject) FXCollections.observableList(javafx.collections.FXCollections.observableList) NotificationService(com.faforever.client.notification.NotificationService) KnownFeaturedMod(com.faforever.client.game.KnownFeaturedMod) TableView(javafx.scene.control.TableView) Pane(javafx.scene.layout.Pane) ReportAction(com.faforever.client.notification.ReportAction) SimpleFloatProperty(javafx.beans.property.SimpleFloatProperty) StringCell(com.faforever.client.fx.StringCell) TextField(javafx.scene.control.TextField) Logger(org.slf4j.Logger) Node(javafx.scene.Node) MethodHandles(java.lang.invoke.MethodHandles) AbstractViewController(com.faforever.client.fx.AbstractViewController) DismissAction(com.faforever.client.notification.DismissAction) Assert(com.faforever.client.util.Assert) Component(org.springframework.stereotype.Component) Severity(com.faforever.client.notification.Severity) Validator(com.faforever.client.util.Validator) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) I18n(com.faforever.client.i18n.I18n) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) SimpleFloatProperty(javafx.beans.property.SimpleFloatProperty)

Aggregations

StringCell (com.faforever.client.fx.StringCell)4 I18n (com.faforever.client.i18n.I18n)4 Node (javafx.scene.Node)4 TableColumn (javafx.scene.control.TableColumn)4 TableView (javafx.scene.control.TableView)4 Inject (javax.inject.Inject)4 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)4 Scope (org.springframework.context.annotation.Scope)4 Component (org.springframework.stereotype.Component)4 AbstractViewController (com.faforever.client.fx.AbstractViewController)3 MapService (com.faforever.client.map.MapService)3 PreviewSize (com.faforever.client.map.MapServiceImpl.PreviewSize)3 UiService (com.faforever.client.theme.UiService)3 Platform (javafx.application.Platform)3 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)3 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)3 ObservableList (javafx.collections.ObservableList)3 NodeTableCell (com.faforever.client.fx.NodeTableCell)2 Game (com.faforever.client.game.Game)2 GameService (com.faforever.client.game.GameService)2