Skip to content
Snippets Groups Projects
Commit aaa3f025 authored by HSoreide's avatar HSoreide
Browse files

Make searchbar active and searchbutton defaut when opening the view to add ingredients to fridge

parent cb5bf851
No related branches found
No related tags found
2 merge requests!42Hs frontend recipes,!41Hs frontend recipes
package no.ntnu.idatt1002.demo.controller;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
......@@ -54,6 +55,14 @@ public class AddIngredientController implements Initializable {
}
private List<String> searchList(String searchWords, String[] listOfStrings) {
String[] searchWordsArray = searchWords.trim().split(" ");
return Arrays.stream(listOfStrings).filter((in) -> {
return Arrays.stream(searchWordsArray).allMatch((word) ->
in.toLowerCase().contains(word.toLowerCase()));
}).collect(Collectors.toList());
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
......@@ -65,16 +74,12 @@ public class AddIngredientController implements Initializable {
ingredientsList = stringIngredients.stream().toArray(String[] ::new);
ingredients = FXCollections.observableArrayList(stringIngredients);
// Fill list with ingredients
listView.setItems(ingredients.sorted());
listView.setItems(ingredients);
}
Platform.runLater(() -> searchBar.requestFocus());
private List<String> searchList(String searchWords, String[] listOfStrings) {
String[] searchWordsArray = searchWords.trim().split(" ");
return Arrays.stream(listOfStrings).filter((in) -> {
return Arrays.stream(searchWordsArray).allMatch((word) ->
in.toLowerCase().contains(word.toLowerCase()));
}).collect(Collectors.toList());
}
}
......@@ -18,3 +18,4 @@ BUTTER
GARLIC_CLOVE
HAM
BROCCOLI
OIL
......@@ -47,7 +47,7 @@
</ListView>
<Pane prefHeight="81.0" prefWidth="600.0">
<children>
<Button id="button-style" fx:id="addBtn" defaultButton="true" layoutX="275.0" layoutY="7.0" mnemonicParsing="false" onAction="#addToFridge" styleClass="button-style" stylesheets="@../style.css" text="ADD">
<Button id="button-style" fx:id="addBtn" layoutX="275.0" layoutY="7.0" mnemonicParsing="false" onAction="#addToFridge" styleClass="button-style" stylesheets="@../style.css" text="ADD">
<font>
<Font size="14.0" />
</font>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment