Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to SearchTextField #173

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions gemsfx/src/main/java/com/dlsc/gemsfx/SearchTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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(); }
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -331,7 +336,6 @@ public final void setMaxHistorySize(int maxHistorySize) {

private ObjectProperty<Node> historyPlaceholder = new SimpleObjectProperty<>(this, "historyPlaceholder");


/**
* Returns the property representing the history placeholder node.
*
Expand All @@ -352,26 +356,26 @@ public final void setHistoryPlaceholder(Node historyPlaceholder) {
historyPlaceholderProperty().set(historyPlaceholder);
}

private ObjectProperty<Callback<ListView<String>, ListCell<String>>> cellFactory;
private ObjectProperty<Callback<ListView<String>, ListCell<String>>> historyCellFactory;

public final Callback<ListView<String>, ListCell<String>> getCellFactory() {
return cellFactory == null ? null : cellFactory.get();
public final Callback<ListView<String>, ListCell<String>> getHistoryCellFactory() {
return historyCellFactory == null ? null : historyCellFactory.get();
}

/**
* The cell factory for the history popup list view.
*
* @return the cell factory
*/
public final ObjectProperty<Callback<ListView<String>, ListCell<String>>> cellFactoryProperty() {
if (cellFactory == null) {
cellFactory = new SimpleObjectProperty<>(this, "cellFactory");
public final ObjectProperty<Callback<ListView<String>, ListCell<String>>> historyCellFactoryProperty() {
if (historyCellFactory == null) {
historyCellFactory = new SimpleObjectProperty<>(this, "historyCellFactory");
}
return cellFactory;
return historyCellFactory;
}

public final void setCellFactory(Callback<ListView<String>, ListCell<String>> cellFactory) {
cellFactoryProperty().set(cellFactory);
public final void setHistoryCellFactory(Callback<ListView<String>, ListCell<String>> historyCellFactory) {
historyCellFactoryProperty().set(historyCellFactory);
}

private BooleanProperty enableHistoryPopup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
21 changes: 10 additions & 11 deletions gemsfx/src/main/resources/com/dlsc/gemsfx/search-text-field.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/* -----------------------------------------------------------------------
Expand Down
Loading