Skip to content

Commit

Permalink
Refactor FilterView properties: Deprecate setTitleLabel and setSubtit…
Browse files Browse the repository at this point in the history
…leLabel, setTitlePostfixLabel

Deprecated setTitleLabel, setSubtitleLabel and setTitlePostfixLabel in FilterView to streamline API usage.
Introduced setTitleGraphic, setSubtitleGraphic, setTitlePostfixGraphic  methods to handle graphic nodes.
This refactor provides a more consistent and intuitive API, aligning with common JavaFX conventions.
  • Loading branch information
leewyatt committed Nov 1, 2024
1 parent 5529754 commit 87b74b5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.materialdesign.MaterialDesign;

import java.time.LocalDate;

Expand All @@ -23,7 +25,12 @@ public class FilterViewApp extends Application {
public void start(Stage stage) {
FilterView<Person> filterView = new FilterView<>();
filterView.setTitle("Title Here");
filterView.setTitleGraphic(new FontIcon(MaterialDesign.MDI_FLAG));
filterView.setSubtitle("Subtitle can be displayed here");
filterView.setSubtitleGraphic(new FontIcon(MaterialDesign.MDI_FILTER));
// filterView.setTitlePostfix("Postfix");
// filterView.setTitlePostfixGraphic(new FontIcon(MaterialDesign.MDI_PEN));

filterView.setTextFilterProvider(text -> person -> person.getFirstName().toLowerCase().contains(text) || person.getLastName().toLowerCase().contains(text));

TableView<Person> tableView = new TableView<>();
Expand Down
49 changes: 24 additions & 25 deletions gemsfx/src/main/java/com/dlsc/gemsfx/FilterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import javafx.collections.transformation.SortedList;
import javafx.scene.Node;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.Skin;
import javafx.util.Callback;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -148,55 +147,55 @@ public void setScrollThreshold(int scrollThreshold) {
this.scrollThreshold.set(scrollThreshold);
}

private final ObjectProperty<Label> titleLabel = new SimpleObjectProperty<>(this, "titleLabel", new Label());
private final ObjectProperty<Node> titleGraphic = new SimpleObjectProperty<>(this, "titleGraphic");

public final Label getTitleLabel() {
return titleLabel.get();
public final Node getTitleGraphic() {
return titleGraphic.get();
}

/**
* The label instance that will be used for displaying the title of the view.
* The graphic node displayed alongside the title label.
*/
public final ObjectProperty<Label> titleLabelProperty() {
return titleLabel;
public final ObjectProperty<Node> titleGraphicProperty() {
return titleGraphic;
}

public final void setTitleLabel(Label titleLabel) {
this.titleLabel.set(titleLabel);
public final void setTitleGraphic(Node titleGraphic) {
this.titleGraphic.set(titleGraphic);
}

private final ObjectProperty<Label> titlePostfixLabel = new SimpleObjectProperty<>(this, "titlePostfixLabel", new Label());
private final ObjectProperty<Node> titlePostfixGraphic = new SimpleObjectProperty<>(this, "titlePostfixGraphic");

public final Label getTitlePostfixLabel() {
return titlePostfixLabel.get();
public final Node getTitlePostfixGraphic() {
return titlePostfixGraphic.get();
}

/**
* The label instance that will be used for displaying the title postfix text of the view.
* The graphic node displayed alongside the title postfix label.
*/
public final ObjectProperty<Label> titlePostfixLabelProperty() {
return titlePostfixLabel;
public final ObjectProperty<Node> titlePostfixGraphicProperty() {
return titlePostfixGraphic;
}

public final void setTitlePostfixLabel(Label titlePostfixLabel) {
this.titlePostfixLabel.set(titlePostfixLabel);
public final void setTitlePostfixGraphic(Node titlePostfixGraphic) {
this.titlePostfixGraphic.set(titlePostfixGraphic);
}

private final ObjectProperty<Label> subtitleLabel = new SimpleObjectProperty<>(this, "subtitleLabel", new Label());
private final ObjectProperty<Node> subtitleGraphic = new SimpleObjectProperty<>(this, "subtitleGraphic");

public Label getSubtitleLabel() {
return subtitleLabel.get();
public Node getSubtitleGraphic() {
return subtitleGraphic.get();
}

/**
* The label instance that will be used for displaying the subtitle of the view.
* The graphic node displayed alongside the subtitle label.
*/
public ObjectProperty<Label> subtitleLabelProperty() {
return subtitleLabel;
public ObjectProperty<Node> subtitleGraphicProperty() {
return subtitleGraphic;
}

public void setSubtitleLabel(Label subtitleLabel) {
this.subtitleLabel.set(subtitleLabel);
public void setSubtitleGraphic(Node subtitleGraphic) {
this.subtitleGraphic.set(subtitleGraphic);
}

private final BooleanProperty showHeader = new SimpleBooleanProperty(this, "showHeader", true);
Expand Down
54 changes: 28 additions & 26 deletions gemsfx/src/main/java/com/dlsc/gemsfx/skins/FilterViewSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.dlsc.gemsfx.FilterView.Filter;
import com.dlsc.gemsfx.SearchTextField;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.collections.ObservableList;
Expand Down Expand Up @@ -39,20 +38,7 @@ public FilterViewSkin(FilterView<T> view) {
super(view);

searchTextField = view.getSearchTextField();

InvalidationListener updateHeaderListener = it -> updateHeaderBox();
view.titleLabelProperty().addListener(updateHeaderListener);
view.titlePostfixLabelProperty().addListener(updateHeaderListener);
view.subtitleLabelProperty().addListener(updateHeaderListener);

view.extrasProperty().addListener((obs, oldExtras, newExtras) -> {
if (oldExtras != null) {
headerBox.getChildren().remove(oldExtras);
}
if (newExtras != null) {
headerBox.getChildren().add(newExtras);
}
});
createHeaderBox();

filterGroupsPane.getStyleClass().add("filter-groups");
filterGroupsPane.setFillHeight(true);
Expand Down Expand Up @@ -106,36 +92,52 @@ public FilterViewSkin(FilterView<T> view) {
headerBox.visibleProperty().bind(view.showHeaderProperty());
headerBox.managedProperty().bind(view.showHeaderProperty());

updateHeaderBox();
view.extrasProperty().addListener((obs, oldExtras, newExtras) -> {
if (oldExtras != null) {
headerBox.getChildren().remove(oldExtras);
}
if (newExtras != null) {
headerBox.getChildren().add(newExtras);
}
});
}

private void updateHeaderBox() {
private void createHeaderBox() {
FilterView<T> view = getSkinnable();

Label titleLabel = view.getTitleLabel();
titleLabel.textProperty().bind(view.titleProperty());
Label titleLabel = new Label();
titleLabel.getStyleClass().add("title");
titleLabel.textProperty().bind(view.titleProperty());
titleLabel.graphicProperty().bind(view.titleGraphicProperty());
titleLabel.managedProperty().bind(titleLabel.visibleProperty());
titleLabel.visibleProperty().bind(view.titleProperty().isNotEmpty().or(view.titleGraphicProperty().isNotNull()));

Label titlePostfixLabel = view.getTitlePostfixLabel();
titlePostfixLabel.textProperty().bind(view.titlePostfixProperty());
Label titlePostfixLabel = new Label();
titlePostfixLabel.getStyleClass().addAll("title", "title-postfix");
titlePostfixLabel.textProperty().bind(view.titlePostfixProperty());
titlePostfixLabel.graphicProperty().bind(view.titlePostfixGraphicProperty());
titlePostfixLabel.managedProperty().bind(titlePostfixLabel.visibleProperty());
titlePostfixLabel.visibleProperty().bind(view.titlePostfixProperty().isNotEmpty().or(view.titlePostfixGraphicProperty().isNotNull()));

HBox titleBox = new HBox(titleLabel, titlePostfixLabel);
titleBox.getStyleClass().add("title-box");

Label subtitleLabel = view.getSubtitleLabel();
subtitleLabel.textProperty().bind(view.subtitleProperty());
Label subtitleLabel = new Label();
subtitleLabel.getStyleClass().add("subtitle");
subtitleLabel.textProperty().bind(view.subtitleProperty());
subtitleLabel.graphicProperty().bind(view.subtitleGraphicProperty());
subtitleLabel.managedProperty().bind(subtitleLabel.visibleProperty());
subtitleLabel.visibleProperty().bind(view.subtitleProperty().isNotEmpty().or(view.subtitleGraphicProperty().isNotNull()));

VBox titleAndSubtitleBox = new VBox(titleBox, subtitleLabel);
titleAndSubtitleBox.getStyleClass().add("title-subtitle-box");

HBox.setHgrow(titleAndSubtitleBox, Priority.ALWAYS);

headerBox.getChildren().setAll(titleAndSubtitleBox, searchTextField);

if (view.getExtras() != null) {
headerBox.getChildren().setAll(titleAndSubtitleBox, searchTextField, view.getExtras());
} else {
headerBox.getChildren().setAll(titleAndSubtitleBox, searchTextField);
headerBox.getChildren().add(view.getExtras());
}
}

Expand Down

0 comments on commit 87b74b5

Please sign in to comment.