diff --git a/gemsfx/src/main/java/com/dlsc/gemsfx/SearchTextField.java b/gemsfx/src/main/java/com/dlsc/gemsfx/SearchTextField.java index 10c6de4c..57ff9cde 100644 --- a/gemsfx/src/main/java/com/dlsc/gemsfx/SearchTextField.java +++ b/gemsfx/src/main/java/com/dlsc/gemsfx/SearchTextField.java @@ -3,13 +3,19 @@ import com.dlsc.gemsfx.skins.SearchTextFieldHistoryPopup; import javafx.beans.InvalidationListener; import javafx.beans.Observable; -import javafx.beans.property.*; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyBooleanWrapper; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.css.PseudoClass; import javafx.event.ActionEvent; import javafx.event.EventTarget; -import javafx.geometry.Pos; import javafx.scene.Cursor; import javafx.scene.Node; import javafx.scene.control.Label; @@ -91,7 +97,7 @@ public SearchTextField(boolean round) { addEventHandlers(); addPropertyListeners(); - setCellFactory(param -> new RemovableListCell<>((listView, item) -> removeHistory(item))); + setHistoryCellFactory(param -> new RemovableListCell<>((listView, item) -> removeHistory(item))); getUnmodifiableHistory().addListener((Observable it) -> { if (getPreferences() != null) { @@ -118,7 +124,11 @@ private void storeHistory() { private void loadHistory() { Preferences preferences = getPreferences(); if (preferences != null) { - history.setAll(preferences.get("search-items", "").split(",")); + String items = preferences.get("search-items", ""); + if (StringUtils.isNotEmpty(items)) { + history.setAll(items.split(",")); + } + // else { history.clear(); } } } @@ -179,16 +189,11 @@ private StackPane createRightNode() { } private StackPane createLeftNode() { - FontIcon searchIcon = new FontIcon(MaterialDesign.MDI_MAGNIFY); + Region searchIcon = new Region(); searchIcon.getStyleClass().add("search-icon"); + searchIcon.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE); - Region arrow = new Region(); - arrow.getStyleClass().add("arrow"); - arrow.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE); - arrow.managedProperty().bind(arrow.visibleProperty()); - StackPane.setAlignment(arrow, Pos.CENTER_RIGHT); - - StackPane searchIconWrapper = new StackPane(searchIcon, arrow); + StackPane searchIconWrapper = new StackPane(searchIcon); searchIconWrapper.getStyleClass().addAll("wrapper", "search-icon-wrapper"); searchIconWrapper.setOnMouseClicked(this::clickIconWrapperHandler); return searchIconWrapper; @@ -331,7 +336,6 @@ public final void setMaxHistorySize(int maxHistorySize) { private ObjectProperty historyPlaceholder = new SimpleObjectProperty<>(this, "historyPlaceholder"); - /** * Returns the property representing the history placeholder node. * @@ -352,10 +356,10 @@ public final void setHistoryPlaceholder(Node historyPlaceholder) { historyPlaceholderProperty().set(historyPlaceholder); } - private ObjectProperty, ListCell>> cellFactory; + private ObjectProperty, ListCell>> historyCellFactory; - public final Callback, ListCell> getCellFactory() { - return cellFactory == null ? null : cellFactory.get(); + public final Callback, ListCell> getHistoryCellFactory() { + return historyCellFactory == null ? null : historyCellFactory.get(); } /** @@ -363,15 +367,15 @@ public final Callback, ListCell> getCellFactory() { * * @return the cell factory */ - public final ObjectProperty, ListCell>> cellFactoryProperty() { - if (cellFactory == null) { - cellFactory = new SimpleObjectProperty<>(this, "cellFactory"); + public final ObjectProperty, ListCell>> historyCellFactoryProperty() { + if (historyCellFactory == null) { + historyCellFactory = new SimpleObjectProperty<>(this, "historyCellFactory"); } - return cellFactory; + return historyCellFactory; } - public final void setCellFactory(Callback, ListCell> cellFactory) { - cellFactoryProperty().set(cellFactory); + public final void setHistoryCellFactory(Callback, ListCell> historyCellFactory) { + historyCellFactoryProperty().set(historyCellFactory); } private BooleanProperty enableHistoryPopup; diff --git a/gemsfx/src/main/java/com/dlsc/gemsfx/skins/SearchTextFieldHistoryPopupSkin.java b/gemsfx/src/main/java/com/dlsc/gemsfx/skins/SearchTextFieldHistoryPopupSkin.java index 6895b678..65620fb3 100644 --- a/gemsfx/src/main/java/com/dlsc/gemsfx/skins/SearchTextFieldHistoryPopupSkin.java +++ b/gemsfx/src/main/java/com/dlsc/gemsfx/skins/SearchTextFieldHistoryPopupSkin.java @@ -34,7 +34,7 @@ public String getUserAgentStylesheet() { Bindings.bindContent(listView.getItems(), searchTextField.getUnmodifiableHistory()); - listView.cellFactoryProperty().bind(searchTextField.cellFactoryProperty()); + listView.cellFactoryProperty().bind(searchTextField.historyCellFactoryProperty()); listView.placeholderProperty().bind(searchTextField.historyPlaceholderProperty()); listView.setOnMouseClicked(mouseEvent -> { diff --git a/gemsfx/src/main/resources/com/dlsc/gemsfx/search-text-field.css b/gemsfx/src/main/resources/com/dlsc/gemsfx/search-text-field.css index 389442ff..0e4f0173 100644 --- a/gemsfx/src/main/resources/com/dlsc/gemsfx/search-text-field.css +++ b/gemsfx/src/main/resources/com/dlsc/gemsfx/search-text-field.css @@ -37,21 +37,20 @@ -fx-background-color: derive(-fx-base, -10%); } -.search-text-field > .left-pane > .search-icon-wrapper > .ikonli-font-icon, -.search-text-field > .right-pane > .clear-icon-wrapper > .ikonli-font-icon { - -fx-icon-size: 1em; - -fx-icon-color: -fx-text-inner-color; +.search-text-field > .left-pane > .search-icon-wrapper > .search-icon { + -fx-padding: 0.43995em 0.5em; + -fx-background-color: -fx-text-inner-color; + -fx-shape: "M8,2.2c4.1,0,7.4,3.3,7.4,7.4c0,1.8-0.7,3.5-1.8,4.8l0.3,0.3h0.9l5.7,5.7l-1.7,1.7l-5.7-5.7v-0.9l-0.3-0.3 C11.5,16.3,9.8,17,8,17c-4.1,0-7.4-3.3-7.4-7.4S3.9,2.2,8,2.2 M8,4.5c-2.8,0-5.1,2.3-5.1,5.1s2.3,5.1,5.1,5.1s5.1-2.3,5.1-5.1 S10.9,4.5,8,4.5zM16.2,10.7h7.1l-3.5,6.1"; } -.search-text-field > .left-pane > .search-icon-wrapper > .arrow { - -fx-shape: "M 0 0 h 7 l -3.5 4 z"; - -fx-background-color: -fx-text-inner-color; - -fx-padding: 0.25em 0.333em 0 0; - -fx-translate-x: 0.08em; +.search-text-field:disabled-popup > .left-pane > .search-icon-wrapper > .search-icon { + -fx-padding: 0.5em; + -fx-shape: "M9.5,3C13.1,3,16,5.9,16,9.5c0,1.6-0.6,3.1-1.6,4.2l0.3,0.3h0.8l5,5L19,20.5l-5-5v-0.8l-0.3-0.3c-1.1,1-2.6,1.6-4.2,1.6 C5.9,16,3,13.1,3,9.5S5.9,3,9.5,3 M9.5,5C7,5,5,7,5,9.5S7,14,9.5,14S14,12,14,9.5S12,5,9.5,5z"; } -.search-text-field:disabled-popup > .left-pane > .search-icon-wrapper > .arrow { - visibility: hidden; +.search-text-field > .right-pane > .clear-icon-wrapper > .ikonli-font-icon { + -fx-icon-size: 1em; + -fx-icon-color: -fx-text-inner-color; } /* -----------------------------------------------------------------------