hanze/game-client

src/main/java/nl/isygameclient/controllers/GameLibraryController.java in main
Repositories | Summary | Log | Files

GameLibraryController.java (1460B) download


 1package nl.isygameclient.controllers;
 2
 3import com.jfoenix.controls.JFXButton;
 4import com.jfoenix.controls.JFXTextField;
 5import javafx.beans.binding.Bindings;
 6import javafx.collections.FXCollections;
 7import javafx.collections.transformation.FilteredList;
 8import javafx.fxml.FXML;
 9import javafx.fxml.Initializable;
10import javafx.scene.layout.FlowPane;
11import nl.isygameclient.views.GameCardControl;
12
13import java.net.URL;
14import java.util.ResourceBundle;
15
16import static nl.isygameclient.Application.GAMES;
17
18public class GameLibraryController implements Initializable {
19    @FXML
20    public FlowPane gameCards;
21    @FXML
22    public JFXTextField searchTextField;
23    @FXML
24    public JFXButton searchButton;
25    @FXML
26    public JFXButton searchClear;
27    @FXML
28    public JFXButton searchOptions;
29    private FilteredList<GameCardControl> filteredList;
30
31    @Override
32    public void initialize(URL url, ResourceBundle resourceBundle) {
33        filteredList = new FilteredList<>(FXCollections.observableList(GAMES));
34        searchTextField.textProperty().addListener((observable, oldValue, newValue) -> {
35            String searchText = searchTextField.getText().toLowerCase();
36            filteredList.setPredicate(n -> n.getGameTitle().toLowerCase().contains(searchText));
37        });
38        Bindings.bindContent(gameCards.getChildren(), filteredList);
39    }
40
41    @FXML
42    protected void onClearSearchButtonClick() {
43        searchTextField.clear();
44    }
45
46
47}