From 6f7d1b569521f83af27109dba960bea190899d34 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Wed, 26 Aug 2020 16:52:49 +0200 Subject: [PATCH] Improved search function (if name matches exactly, no need to open the window) Improved search result window design --- src/main/java/Controller.java | 36 ++++++------ .../java/SearchResultWindowController.java | 37 +++++------- src/main/java/util/SteamAppsListCache.java | 37 ++++-------- src/main/resources/mainWindow.fxml | 14 +++-- src/main/resources/searchResultWindow.fxml | 56 ++++++++++++------- src/main/resources/stylesheet.css | 18 ++++++ 6 files changed, 108 insertions(+), 90 deletions(-) create mode 100644 src/main/resources/stylesheet.css diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index 0e83eaa..ce82cf6 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -13,7 +13,6 @@ * . */ -import com.jfoenix.controls.*; import javafx.beans.value.ChangeListener; import javafx.collections.FXCollections; import javafx.concurrent.Service; @@ -22,9 +21,7 @@ import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; -import javafx.scene.control.Alert; -import javafx.scene.control.Label; -import javafx.scene.control.Tooltip; +import javafx.scene.control.*; import javafx.stage.*; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.configuration2.ex.ConfigurationException; @@ -68,31 +65,31 @@ public class Controller { @FXML public Label state_label; @FXML - public JFXTextField path_textfield; + public TextField path_textfield; @FXML - public JFXTextField appId_textfield; + public TextField appId_textfield; @FXML - public JFXTextField game_name_textfield; + public TextField game_name_textfield; @FXML - public JFXComboBox language_combobox; + public ComboBox language_combobox; @FXML - public JFXTextArea dlc_textarea; + public TextArea dlc_textarea; @FXML - public JFXCheckBox extra_protection_checkbox; + public CheckBox extra_protection_checkbox; @FXML - public JFXCheckBox offline_checkbox; + public CheckBox offline_checkbox; @FXML - public JFXCheckBox unlock_all_checkbox; + public CheckBox unlock_all_checkbox; @FXML - public JFXButton reset_button; + public Button reset_button; @FXML - public JFXButton save_button; + public Button save_button; @FXML - public JFXButton getAppId_button; + public Button getAppId_button; @FXML - public JFXButton path_button; + public Button path_button; @FXML - public JFXButton retrieveDlcList_button; + public Button retrieveDlcList_button; private String steamApiPathString; public Controller() { @@ -215,6 +212,10 @@ public class Controller { final List games = cache.findListOfGames(game_name_textfield.getText()); if (games.isEmpty()) { appId_textfield.setText("-1"); + } else if (games.size() == 1) { + App game = games.get(0); + game_name_textfield.setText(game.getName()); + appId_textfield.setText(String.valueOf(game.getAppId())); } else { try { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("searchResultWindow.fxml")); @@ -226,6 +227,7 @@ public class Controller { Stage stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); + stage.setResizable(false); //stage.initStyle(StageStyle.UNDECORATED); stage.setTitle("Choose game..."); stage.setScene(new Scene(root1)); diff --git a/src/main/java/SearchResultWindowController.java b/src/main/java/SearchResultWindowController.java index 8b4217f..ded05bd 100644 --- a/src/main/java/SearchResultWindowController.java +++ b/src/main/java/SearchResultWindowController.java @@ -13,13 +13,9 @@ * . */ -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.TableColumn; -import javafx.scene.control.TableView; -import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.control.*; +import javafx.scene.control.cell.TreeItemPropertyValueFactory; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; import javafx.stage.Stage; @@ -34,16 +30,16 @@ public class SearchResultWindowController { @FXML public Button cancelButton; @FXML - public TableView gameTable; + public TreeTableView gameTable; @FXML - public TableColumn appIdCol; + public TreeTableColumn appIdCol; @FXML - public TableColumn nameCol; + public TreeTableColumn nameCol; public Controller parent; private long lastTime; - private boolean isdblClicked; + private boolean isDblClicked; public SearchResultWindowController() { } @@ -53,18 +49,15 @@ public class SearchResultWindowController { } public void initMe(List games) { - ObservableList data = FXCollections.observableArrayList(games); - try { - appIdCol.setCellValueFactory(new PropertyValueFactory<>("appId")); - nameCol.setCellValueFactory(new PropertyValueFactory<>("name")); - gameTable.setItems(data); - } catch (Exception e) { - e.printStackTrace(); - } + TreeItem root = new TreeItem<>(); + appIdCol.setCellValueFactory(new TreeItemPropertyValueFactory<>("appId")); + nameCol.setCellValueFactory(new TreeItemPropertyValueFactory<>("name")); + games.forEach(game -> root.getChildren().add(new TreeItem<>(game))); + gameTable.setRoot(root); } public void confirm() { - App app = gameTable.getSelectionModel().getSelectedItem(); + App app = gameTable.getSelectionModel().getSelectedItem().getValue(); parent.game_name_textfield.setText(app.getName()); parent.appId_textfield.setText(String.valueOf(app.getAppId())); Stage current = (Stage) okButton.getScene().getWindow(); @@ -88,11 +81,11 @@ public class SearchResultWindowController { long currentTime = System.currentTimeMillis(); if (lastTime != 0 && currentTime != 0) { diff = currentTime - lastTime; - isdblClicked = (diff <= 215); + isDblClicked = (diff <= 215); } lastTime = currentTime; - if (isdblClicked) { - App app = gameTable.getSelectionModel().getSelectedItem(); + if (isDblClicked) { + App app = gameTable.getSelectionModel().getSelectedItem().getValue(); parent.game_name_textfield.setText(app.getName()); parent.appId_textfield.setText(String.valueOf(app.getAppId())); Stage current = (Stage) gameTable.getScene().getWindow(); diff --git a/src/main/java/util/SteamAppsListCache.java b/src/main/java/util/SteamAppsListCache.java index 41446c2..591c5bb 100644 --- a/src/main/java/util/SteamAppsListCache.java +++ b/src/main/java/util/SteamAppsListCache.java @@ -95,35 +95,18 @@ public class SteamAppsListCache { public List findListOfGames(String name) { List> match = FuzzySearch.extractSorted(name, list.getSteamAppsList(), app -> app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""), 80); - return match.stream().map(BoundExtractedResult::getReferent).collect(Collectors.toList()); + List collect = match.stream().map(BoundExtractedResult::getReferent).collect(Collectors.toList()); + for (App app : collect) { + if (app.getName().replaceAll("[^a-zA-Z0-9\\s+]", "") + .equalsIgnoreCase(name.replaceAll("[^a-zA-Z0-9\\s+]", ""))) { + collect = new ArrayList<>(); + collect.add(app); + break; + } + } + return collect; } - // public App findGame(String name) { - // List> match = FuzzySearch.extractSorted(name, list.getSteamAppsList(), app -> - // app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""), 80); - // /*System.out.println("\n\n\n==== Top 25 results for \"" + name + "\": ===="); - // for (BoundExtractedResult result : match) { - // System.out.println(result.getReferent().getName() + " - " + - // result.getIndex() + " - " + - // result.getScore()); - // } - // System.out.println("\n\n\n");*/ - // return match.get(0).getReferent(); - // /*for (App app : list.getSteamAppsList()) { - // if (app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", "") - // .startsWith(name.toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""))) { - // return app; - // } - // } - // for (App app : list.getSteamAppsList()) { - // if (app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", "") - // .contains(name.toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""))) { - // return app; - // } - // }*/ - // //return null; - // } - private void getListFromApi() { System.out.println("Trying to get SteamAppList from API..."); List apps = getApps(); diff --git a/src/main/resources/mainWindow.fxml b/src/main/resources/mainWindow.fxml index 0c895a3..ebb2d7c 100644 --- a/src/main/resources/mainWindow.fxml +++ b/src/main/resources/mainWindow.fxml @@ -27,6 +27,7 @@ ~ . --> + @@ -51,7 +52,7 @@ + GridPane.columnIndex="2"> @@ -59,7 +60,7 @@ + GridPane.columnIndex="1" GridPane.rowIndex="1"> @@ -78,13 +79,16 @@ GridPane.rowIndex="6"/> + text="Get DLCs for AppID" GridPane.rowIndex="7"/> + text="Save" GridPane.columnIndex="1" GridPane.rowIndex="7"/> + text="Reset" GridPane.columnIndex="2" GridPane.rowIndex="7"/> diff --git a/src/main/resources/searchResultWindow.fxml b/src/main/resources/searchResultWindow.fxml index 277fa5f..600c0fd 100644 --- a/src/main/resources/searchResultWindow.fxml +++ b/src/main/resources/searchResultWindow.fxml @@ -1,35 +1,53 @@ - - - + + + + + + + + - + + + - + - + -