Improved search function (if name matches exactly, no need to open the window)

Improved search result window design
This commit is contained in:
Jeddunk 2020-08-26 16:52:49 +02:00
parent c2254856da
commit 6f7d1b5695
6 changed files with 108 additions and 90 deletions

View File

@ -13,7 +13,6 @@
* <https://www.gnu.org/licenses/>. * <https://www.gnu.org/licenses/>.
*/ */
import com.jfoenix.controls.*;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.concurrent.Service; import javafx.concurrent.Service;
@ -22,9 +21,7 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Alert; import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.stage.*; import javafx.stage.*;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.configuration2.ex.ConfigurationException; import org.apache.commons.configuration2.ex.ConfigurationException;
@ -68,31 +65,31 @@ public class Controller {
@FXML @FXML
public Label state_label; public Label state_label;
@FXML @FXML
public JFXTextField path_textfield; public TextField path_textfield;
@FXML @FXML
public JFXTextField appId_textfield; public TextField appId_textfield;
@FXML @FXML
public JFXTextField game_name_textfield; public TextField game_name_textfield;
@FXML @FXML
public JFXComboBox<String> language_combobox; public ComboBox<String> language_combobox;
@FXML @FXML
public JFXTextArea dlc_textarea; public TextArea dlc_textarea;
@FXML @FXML
public JFXCheckBox extra_protection_checkbox; public CheckBox extra_protection_checkbox;
@FXML @FXML
public JFXCheckBox offline_checkbox; public CheckBox offline_checkbox;
@FXML @FXML
public JFXCheckBox unlock_all_checkbox; public CheckBox unlock_all_checkbox;
@FXML @FXML
public JFXButton reset_button; public Button reset_button;
@FXML @FXML
public JFXButton save_button; public Button save_button;
@FXML @FXML
public JFXButton getAppId_button; public Button getAppId_button;
@FXML @FXML
public JFXButton path_button; public Button path_button;
@FXML @FXML
public JFXButton retrieveDlcList_button; public Button retrieveDlcList_button;
private String steamApiPathString; private String steamApiPathString;
public Controller() { public Controller() {
@ -215,6 +212,10 @@ public class Controller {
final List<App> games = cache.findListOfGames(game_name_textfield.getText()); final List<App> games = cache.findListOfGames(game_name_textfield.getText());
if (games.isEmpty()) { if (games.isEmpty()) {
appId_textfield.setText("-1"); 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 { } else {
try { try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("searchResultWindow.fxml")); FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("searchResultWindow.fxml"));
@ -226,6 +227,7 @@ public class Controller {
Stage stage = new Stage(); Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL); stage.initModality(Modality.APPLICATION_MODAL);
stage.setResizable(false);
//stage.initStyle(StageStyle.UNDECORATED); //stage.initStyle(StageStyle.UNDECORATED);
stage.setTitle("Choose game..."); stage.setTitle("Choose game...");
stage.setScene(new Scene(root1)); stage.setScene(new Scene(root1));

View File

@ -13,13 +13,9 @@
* <https://www.gnu.org/licenses/>. * <https://www.gnu.org/licenses/>.
*/ */
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.*;
import javafx.scene.control.TableColumn; import javafx.scene.control.cell.TreeItemPropertyValueFactory;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseButton; import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -34,16 +30,16 @@ public class SearchResultWindowController {
@FXML @FXML
public Button cancelButton; public Button cancelButton;
@FXML @FXML
public TableView<App> gameTable; public TreeTableView<App> gameTable;
@FXML @FXML
public TableColumn<App, Integer> appIdCol; public TreeTableColumn<App, Integer> appIdCol;
@FXML @FXML
public TableColumn<App, String> nameCol; public TreeTableColumn<App, String> nameCol;
public Controller parent; public Controller parent;
private long lastTime; private long lastTime;
private boolean isdblClicked; private boolean isDblClicked;
public SearchResultWindowController() { public SearchResultWindowController() {
} }
@ -53,18 +49,15 @@ public class SearchResultWindowController {
} }
public void initMe(List<App> games) { public void initMe(List<App> games) {
ObservableList<App> data = FXCollections.observableArrayList(games); TreeItem<App> root = new TreeItem<>();
try { appIdCol.setCellValueFactory(new TreeItemPropertyValueFactory<>("appId"));
appIdCol.setCellValueFactory(new PropertyValueFactory<>("appId")); nameCol.setCellValueFactory(new TreeItemPropertyValueFactory<>("name"));
nameCol.setCellValueFactory(new PropertyValueFactory<>("name")); games.forEach(game -> root.getChildren().add(new TreeItem<>(game)));
gameTable.setItems(data); gameTable.setRoot(root);
} catch (Exception e) {
e.printStackTrace();
}
} }
public void confirm() { public void confirm() {
App app = gameTable.getSelectionModel().getSelectedItem(); App app = gameTable.getSelectionModel().getSelectedItem().getValue();
parent.game_name_textfield.setText(app.getName()); parent.game_name_textfield.setText(app.getName());
parent.appId_textfield.setText(String.valueOf(app.getAppId())); parent.appId_textfield.setText(String.valueOf(app.getAppId()));
Stage current = (Stage) okButton.getScene().getWindow(); Stage current = (Stage) okButton.getScene().getWindow();
@ -88,11 +81,11 @@ public class SearchResultWindowController {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
if (lastTime != 0 && currentTime != 0) { if (lastTime != 0 && currentTime != 0) {
diff = currentTime - lastTime; diff = currentTime - lastTime;
isdblClicked = (diff <= 215); isDblClicked = (diff <= 215);
} }
lastTime = currentTime; lastTime = currentTime;
if (isdblClicked) { if (isDblClicked) {
App app = gameTable.getSelectionModel().getSelectedItem(); App app = gameTable.getSelectionModel().getSelectedItem().getValue();
parent.game_name_textfield.setText(app.getName()); parent.game_name_textfield.setText(app.getName());
parent.appId_textfield.setText(String.valueOf(app.getAppId())); parent.appId_textfield.setText(String.valueOf(app.getAppId()));
Stage current = (Stage) gameTable.getScene().getWindow(); Stage current = (Stage) gameTable.getScene().getWindow();

View File

@ -95,34 +95,17 @@ public class SteamAppsListCache {
public List<App> findListOfGames(String name) { public List<App> findListOfGames(String name) {
List<BoundExtractedResult<App>> match = FuzzySearch.extractSorted(name, list.getSteamAppsList(), app -> List<BoundExtractedResult<App>> match = FuzzySearch.extractSorted(name, list.getSteamAppsList(), app ->
app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""), 80); app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""), 80);
return match.stream().map(BoundExtractedResult::getReferent).collect(Collectors.toList()); List<App> 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<BoundExtractedResult<App>> 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<App> 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() { private void getListFromApi() {
System.out.println("Trying to get SteamAppList from API..."); System.out.println("Trying to get SteamAppList from API...");

View File

@ -27,6 +27,7 @@
~ <https://www.gnu.org/licenses/>. ~ <https://www.gnu.org/licenses/>.
--> -->
<?import java.net.URL?>
<GridPane hgap="10.0" minHeight="400.0" minWidth="655.0" vgap="10.0" xmlns="http://javafx.com/javafx/8.0.171" <GridPane hgap="10.0" minHeight="400.0" minWidth="655.0" vgap="10.0" xmlns="http://javafx.com/javafx/8.0.171"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller"> xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller">
<columnConstraints> <columnConstraints>
@ -51,7 +52,7 @@
<JFXTextField fx:id="path_textfield" promptText="Path to game's steam_api(64).dll..." GridPane.columnSpan="2"/> <JFXTextField fx:id="path_textfield" promptText="Path to game's steam_api(64).dll..." GridPane.columnSpan="2"/>
<JFXButton fx:id="path_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" <JFXButton fx:id="path_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minHeight="-Infinity" minWidth="-Infinity" onAction="#openFileChooser" ripplerFill="BLACK" minHeight="-Infinity" minWidth="-Infinity" onAction="#openFileChooser" ripplerFill="BLACK"
style="-fx-background-color: #ddd;" GridPane.columnIndex="2"> GridPane.columnIndex="2">
<graphic> <graphic>
<FontAwesomeIconView glyphName="FOLDER_OPEN" glyphSize="24"/> <FontAwesomeIconView glyphName="FOLDER_OPEN" glyphSize="24"/>
</graphic> </graphic>
@ -59,7 +60,7 @@
<JFXTextField fx:id="game_name_textfield" promptText="Game..." GridPane.rowIndex="1"/> <JFXTextField fx:id="game_name_textfield" promptText="Game..." GridPane.rowIndex="1"/>
<JFXButton fx:id="getAppId_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" <JFXButton fx:id="getAppId_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minHeight="-Infinity" minWidth="-Infinity" onAction="#getAppId" ripplerFill="BLACK" minHeight="-Infinity" minWidth="-Infinity" onAction="#getAppId" ripplerFill="BLACK"
style="-fx-background-color: #ddd;" GridPane.columnIndex="1" GridPane.rowIndex="1"> GridPane.columnIndex="1" GridPane.rowIndex="1">
<graphic> <graphic>
<FontAwesomeIconView glyphName="SEARCH" glyphSize="24"/> <FontAwesomeIconView glyphName="SEARCH" glyphSize="24"/>
</graphic> </graphic>
@ -78,13 +79,16 @@
GridPane.rowIndex="6"/> GridPane.rowIndex="6"/>
<JFXButton fx:id="retrieveDlcList_button" maxHeight="1.7976931348623157E308" maxWidth="-Infinity" <JFXButton fx:id="retrieveDlcList_button" maxHeight="1.7976931348623157E308" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" onAction="#getDlcList" ripplerFill="BLACK" minHeight="-Infinity" minWidth="-Infinity" onAction="#getDlcList" ripplerFill="BLACK"
style="-fx-background-color: #ddd;" text="Get DLCs for AppID" GridPane.rowIndex="7"/> text="Get DLCs for AppID" GridPane.rowIndex="7"/>
<JFXButton fx:id="save_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" <JFXButton fx:id="save_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minHeight="-Infinity" minWidth="-Infinity" onAction="#save" ripplerFill="BLACK" minHeight="-Infinity" minWidth="-Infinity" onAction="#save" ripplerFill="BLACK"
style="-fx-background-color: #ddd;" text="Save" GridPane.columnIndex="1" GridPane.rowIndex="7"/> text="Save" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
<JFXButton fx:id="reset_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" <JFXButton fx:id="reset_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minHeight="-Infinity" minWidth="-Infinity" onAction="#resetFromButton" ripplerFill="BLACK" minHeight="-Infinity" minWidth="-Infinity" onAction="#resetFromButton" ripplerFill="BLACK"
style="-fx-background-color: #ddd;" text="Reset" GridPane.columnIndex="2" GridPane.rowIndex="7"/> text="Reset" GridPane.columnIndex="2" GridPane.rowIndex="7"/>
<Label fx:id="state_label" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" <Label fx:id="state_label" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minHeight="-Infinity" minWidth="-Infinity" GridPane.columnSpan="2147483647" GridPane.rowIndex="8"/> minHeight="-Infinity" minWidth="-Infinity" GridPane.columnSpan="2147483647" GridPane.rowIndex="8"/>
<stylesheets>
<URL value="@stylesheet.css" />
</stylesheets>
</GridPane> </GridPane>

View File

@ -1,35 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?> <?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.control.*?> <?import com.jfoenix.controls.JFXTreeTableView?>
<?import javafx.scene.layout.*?> <?import java.net.URL?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TreeTableColumn?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="655.0" <!--
prefWidth="420.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" ~ Auto-CreamAPI
fx:controller="SearchResultWindowController"> ~ Copyright (C) 2020 Jeddunk
~
~ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
~ License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
~ version.
~
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
~ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License along with this program. If not, see
~ <https://www.gnu.org/licenses/>.
-->
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="655.0" prefWidth="420.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="SearchResultWindowController">
<opaqueInsets> <opaqueInsets>
<Insets/> <Insets />
</opaqueInsets> </opaqueInsets>
<padding> <padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/> <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding> </padding>
<Label maxWidth="1.7976931348623157E308" text="Choose a game from the list below:"/> <Label maxWidth="1.7976931348623157E308" text="Choose a game from the list below:" />
<TableView fx:id="gameTable" maxHeight="1.7976931348623157E308" onMouseClicked="#doubleclickConfirm" <JFXTreeTableView fx:id="gameTable" fixedCellSize="28.0" maxHeight="1.7976931348623157E308" onMouseClicked="#doubleclickConfirm" prefHeight="570.0" prefWidth="400.0" showRoot="false">
prefHeight="570.0" prefWidth="400.0">
<columns> <columns>
<TableColumn fx:id="appIdCol" editable="false" maxWidth="100.0" minWidth="100.0" prefWidth="100.0" <TreeTableColumn fx:id="appIdCol" editable="false" maxWidth="100.0" minWidth="100.0" prefWidth="100.0" resizable="false" text="AppID" />
text="AppID"/> <TreeTableColumn fx:id="nameCol" editable="false" maxWidth="285.0" minWidth="285.0" prefWidth="285.0" resizable="false" text="Name" />
<TableColumn fx:id="nameCol" editable="false" maxWidth="285.0" minWidth="285.0" prefWidth="285.0"
text="Name"/>
</columns> </columns>
<VBox.margin> <VBox.margin>
<Insets bottom="10.0" top="10.0"/> <Insets bottom="10.0" top="10.0" />
</VBox.margin> </VBox.margin>
</TableView> </JFXTreeTableView>
<ButtonBar prefHeight="40.0" prefWidth="200.0"> <ButtonBar prefHeight="40.0" prefWidth="200.0">
<buttons> <buttons>
<Button fx:id="okButton" mnemonicParsing="false" onAction="#confirm" text="OK"/> <JFXButton fx:id="okButton" mnemonicParsing="false" onAction="#confirm" text="OK" ripplerFill="BLACK" />
<Button fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel"/> <JFXButton fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel" ripplerFill="BLACK" />
</buttons> </buttons>
</ButtonBar> </ButtonBar>
<stylesheets>
<URL value="@stylesheet.css" />
</stylesheets>
</VBox> </VBox>

View File

@ -0,0 +1,18 @@
/*
* Auto-CreamAPI
* Copyright (C) 2020 Jeddunk
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
JFXButton {
-fx-background-color: #ddd;
}