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/>.
*/
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<String> language_combobox;
public ComboBox<String> 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<App> 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));

View File

@ -13,13 +13,9 @@
* <https://www.gnu.org/licenses/>.
*/
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<App> gameTable;
public TreeTableView<App> gameTable;
@FXML
public TableColumn<App, Integer> appIdCol;
public TreeTableColumn<App, Integer> appIdCol;
@FXML
public TableColumn<App, String> nameCol;
public TreeTableColumn<App, String> 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<App> games) {
ObservableList<App> data = FXCollections.observableArrayList(games);
try {
appIdCol.setCellValueFactory(new PropertyValueFactory<>("appId"));
nameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
gameTable.setItems(data);
} catch (Exception e) {
e.printStackTrace();
}
TreeItem<App> 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();

View File

@ -95,35 +95,18 @@ public class SteamAppsListCache {
public List<App> findListOfGames(String name) {
List<BoundExtractedResult<App>> 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<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() {
System.out.println("Trying to get SteamAppList from API...");
List<App> apps = getApps();

View File

@ -27,6 +27,7 @@
~ <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"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller">
<columnConstraints>
@ -51,7 +52,7 @@
<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"
minHeight="-Infinity" minWidth="-Infinity" onAction="#openFileChooser" ripplerFill="BLACK"
style="-fx-background-color: #ddd;" GridPane.columnIndex="2">
GridPane.columnIndex="2">
<graphic>
<FontAwesomeIconView glyphName="FOLDER_OPEN" glyphSize="24"/>
</graphic>
@ -59,7 +60,7 @@
<JFXTextField fx:id="game_name_textfield" promptText="Game..." GridPane.rowIndex="1"/>
<JFXButton fx:id="getAppId_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
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>
<FontAwesomeIconView glyphName="SEARCH" glyphSize="24"/>
</graphic>
@ -78,13 +79,16 @@
GridPane.rowIndex="6"/>
<JFXButton fx:id="retrieveDlcList_button" maxHeight="1.7976931348623157E308" maxWidth="-Infinity"
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"
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"
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"
minHeight="-Infinity" minWidth="-Infinity" GridPane.columnSpan="2147483647" GridPane.rowIndex="8"/>
<stylesheets>
<URL value="@stylesheet.css" />
</stylesheets>
</GridPane>

View File

@ -1,35 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXTreeTableView?>
<?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"
fx:controller="SearchResultWindowController">
<!--
~ 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/>.
-->
<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>
<Insets/>
<Insets />
</opaqueInsets>
<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>
<Label maxWidth="1.7976931348623157E308" text="Choose a game from the list below:"/>
<TableView fx:id="gameTable" maxHeight="1.7976931348623157E308" onMouseClicked="#doubleclickConfirm"
prefHeight="570.0" prefWidth="400.0">
<Label maxWidth="1.7976931348623157E308" text="Choose a game from the list below:" />
<JFXTreeTableView fx:id="gameTable" fixedCellSize="28.0" maxHeight="1.7976931348623157E308" onMouseClicked="#doubleclickConfirm" prefHeight="570.0" prefWidth="400.0" showRoot="false">
<columns>
<TableColumn fx:id="appIdCol" editable="false" maxWidth="100.0" minWidth="100.0" prefWidth="100.0"
text="AppID"/>
<TableColumn fx:id="nameCol" editable="false" maxWidth="285.0" minWidth="285.0" prefWidth="285.0"
text="Name"/>
<TreeTableColumn fx:id="appIdCol" editable="false" maxWidth="100.0" minWidth="100.0" prefWidth="100.0" resizable="false" text="AppID" />
<TreeTableColumn fx:id="nameCol" editable="false" maxWidth="285.0" minWidth="285.0" prefWidth="285.0" resizable="false" text="Name" />
</columns>
<VBox.margin>
<Insets bottom="10.0" top="10.0"/>
<Insets bottom="10.0" top="10.0" />
</VBox.margin>
</TableView>
</JFXTreeTableView>
<ButtonBar prefHeight="40.0" prefWidth="200.0">
<buttons>
<Button fx:id="okButton" mnemonicParsing="false" onAction="#confirm" text="OK"/>
<Button fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel"/>
<JFXButton fx:id="okButton" mnemonicParsing="false" onAction="#confirm" text="OK" ripplerFill="BLACK" />
<JFXButton fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel" ripplerFill="BLACK" />
</buttons>
</ButtonBar>
<stylesheets>
<URL value="@stylesheet.css" />
</stylesheets>
</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;
}