game-client

Play TicTacToe and Reversi
Log | Files | Refs

GameLibraryController.java (1460B)


      1 package nl.isygameclient.controllers;
      2 
      3 import com.jfoenix.controls.JFXButton;
      4 import com.jfoenix.controls.JFXTextField;
      5 import javafx.beans.binding.Bindings;
      6 import javafx.collections.FXCollections;
      7 import javafx.collections.transformation.FilteredList;
      8 import javafx.fxml.FXML;
      9 import javafx.fxml.Initializable;
     10 import javafx.scene.layout.FlowPane;
     11 import nl.isygameclient.views.GameCardControl;
     12 
     13 import java.net.URL;
     14 import java.util.ResourceBundle;
     15 
     16 import static nl.isygameclient.Application.GAMES;
     17 
     18 public 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 }