diff --git a/gemsfx-demo/src/main/java/com/dlsc/gemsfx/demo/FilterViewApp.java b/gemsfx-demo/src/main/java/com/dlsc/gemsfx/demo/FilterViewApp.java index 0b9eb06e..61875bf4 100644 --- a/gemsfx-demo/src/main/java/com/dlsc/gemsfx/demo/FilterViewApp.java +++ b/gemsfx-demo/src/main/java/com/dlsc/gemsfx/demo/FilterViewApp.java @@ -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; @@ -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<>(); diff --git a/gemsfx/src/main/java/com/dlsc/gemsfx/FilterView.java b/gemsfx/src/main/java/com/dlsc/gemsfx/FilterView.java index 8c7b0b98..37ae76d3 100644 --- a/gemsfx/src/main/java/com/dlsc/gemsfx/FilterView.java +++ b/gemsfx/src/main/java/com/dlsc/gemsfx/FilterView.java @@ -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; @@ -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); diff --git a/gemsfx/src/main/java/com/dlsc/gemsfx/skins/FilterViewSkin.java b/gemsfx/src/main/java/com/dlsc/gemsfx/skins/FilterViewSkin.java index 59f70561..0e1490e9 100644 --- a/gemsfx/src/main/java/com/dlsc/gemsfx/skins/FilterViewSkin.java +++ b/gemsfx/src/main/java/com/dlsc/gemsfx/skins/FilterViewSkin.java @@ -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; @@ -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); @@ -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()); } }