Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed Aug 24, 2023
1 parent 4db4651 commit 44df496
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 8 additions & 6 deletions gemsfx/src/main/java/com/dlsc/gemsfx/SearchField.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class SearchField<T> extends Control {

private final SearchFieldPopup<T> popup;

private BooleanProperty shouldCommitProperty = new SimpleBooleanProperty(this, "shouldCommit", false);
private final BooleanProperty shouldCommit = new SimpleBooleanProperty(this, "shouldCommit", false);

/**
* Constructs a new spotlight field. The field will set defaults for the
Expand All @@ -80,7 +80,7 @@ public class SearchField<T> extends Control {
public SearchField() {
getStyleClass().add(DEFAULT_STYLE_CLASS);

popup = new SearchFieldPopup<>(this, shouldCommitProperty);
popup = new SearchFieldPopup<>(this, shouldCommit);

editor.textProperty().bindBidirectional(textProperty());
editor.promptTextProperty().bindBidirectional(promptTextProperty());
Expand All @@ -97,7 +97,7 @@ public SearchField() {
}
});

addEventFilter(KeyEvent.KEY_PRESSED, evt -> {
addEventFilter(KeyEvent.ANY, evt -> {
if (evt.getCode().equals(KeyCode.RIGHT) || evt.getCode().equals(KeyCode.ENTER)) {
commit();
evt.consume();
Expand Down Expand Up @@ -231,7 +231,8 @@ public T fromString(String s) {
* item.
*/
public void commit() {
if (shouldCommitProperty.get()) {
if (shouldCommit.get()) {
System.out.println("committing");
committing = true;
try {
T selectedItem = getSelectedItem();
Expand All @@ -249,7 +250,7 @@ public void commit() {
} finally {
committing = false;
}
shouldCommitProperty.set(false);
shouldCommit.set(false);
}
}

Expand Down Expand Up @@ -860,6 +861,7 @@ public static class SearchEvent extends Event {
public static final EventType<SearchEvent> SUGGESTION_SELECTED = new EventType<>(Event.ANY, "SUGGESTION_SELECTED");

private final Object selectedSuggestion;

private final String text;

public static SearchEvent createEventForText(EventType<? extends SearchEvent> eventType, String text) {
Expand All @@ -873,7 +875,7 @@ public static SearchEvent createEventForSuggestion(Object suggestion) {
private SearchEvent(EventType<? extends SearchEvent> eventType, String text, Object suggestion) {
super(eventType);
this.text = text;
this.selectedSuggestion = suggestion;
selectedSuggestion = suggestion;
}

public String getText() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public class SearchFieldPopup<T> extends PopupControl {

public static final String DEFAULT_STYLE_CLASS = "search-field-popup";

private final BooleanProperty shouldCommitProperty;
private final BooleanProperty shouldCommit;

public SearchFieldPopup(SearchField<T> searchField, BooleanProperty shouldCommitProperty) {
public SearchFieldPopup(SearchField<T> searchField, BooleanProperty shouldCommit) {
this.searchField = Objects.requireNonNull(searchField);
this.shouldCommitProperty = shouldCommitProperty;
this.shouldCommit = Objects.requireNonNull(shouldCommit);

minWidthProperty().bind(searchField.widthProperty());

Expand Down Expand Up @@ -108,6 +108,6 @@ private void selectFirstSuggestion() {
}

protected Skin<?> createDefaultSkin() {
return new SearchFieldPopupSkin(this, shouldCommitProperty);
return new SearchFieldPopupSkin<>(this, shouldCommit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class SearchFieldPopupSkin<T> implements Skin<SearchFieldPopup<T>> {
private final SearchFieldPopup<T> control;
private final ListView<T> suggestionList;
private final SearchField<T> searchField;
private BooleanProperty shouldCommit;
private final BooleanProperty shouldCommit;

public SearchFieldPopupSkin(SearchFieldPopup<T> control, BooleanProperty shouldCommit) {
this.control = control;
this.shouldCommit = shouldCommit;
Expand Down

0 comments on commit 44df496

Please sign in to comment.