diff --git a/sampler/src/main/java/atlantafx/sampler/event/NavEvent.java b/sampler/src/main/java/atlantafx/sampler/event/NavEvent.java new file mode 100644 index 0000000..be0f818 --- /dev/null +++ b/sampler/src/main/java/atlantafx/sampler/event/NavEvent.java @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: MIT */ + +package atlantafx.sampler.event; + +import atlantafx.sampler.page.Page; + +public final class NavEvent extends Event { + + private final Class page; + + public NavEvent(Class page) { + this.page = page; + } + + public Class getPage() { + return page; + } + + @Override + public String toString() { + return "NavEvent{" + + "page=" + page + + "} " + super.toString(); + } +} diff --git a/sampler/src/main/java/atlantafx/sampler/layout/MainModel.java b/sampler/src/main/java/atlantafx/sampler/layout/MainModel.java index b07dfde..2bffbda 100644 --- a/sampler/src/main/java/atlantafx/sampler/layout/MainModel.java +++ b/sampler/src/main/java/atlantafx/sampler/layout/MainModel.java @@ -5,6 +5,8 @@ package atlantafx.sampler.layout; import static atlantafx.sampler.layout.MainModel.SubLayer.PAGE; import static atlantafx.sampler.layout.MainModel.SubLayer.SOURCE_CODE; +import atlantafx.sampler.event.DefaultEventBus; +import atlantafx.sampler.event.NavEvent; import atlantafx.sampler.page.Page; import atlantafx.sampler.page.components.AccordionPage; import atlantafx.sampler.page.components.AnimationsPage; @@ -94,6 +96,10 @@ public class MainModel { .toList(); } + public MainModel() { + DefaultEventBus.getInstance().subscribe(NavEvent.class, e -> navigate(e.getPage())); + } + /////////////////////////////////////////////////////////////////////////// // Properties // /////////////////////////////////////////////////////////////////////////// diff --git a/sampler/src/main/java/atlantafx/sampler/layout/Nav.java b/sampler/src/main/java/atlantafx/sampler/layout/Nav.java index 62656ae..10cdeb4 100644 --- a/sampler/src/main/java/atlantafx/sampler/layout/Nav.java +++ b/sampler/src/main/java/atlantafx/sampler/layout/Nav.java @@ -3,19 +3,47 @@ package atlantafx.sampler.layout; import atlantafx.sampler.page.Page; +import atlantafx.sampler.page.components.BreadcrumbsPage; +import atlantafx.sampler.page.components.CalendarPage; +import atlantafx.sampler.page.components.CardPage; +import atlantafx.sampler.page.components.CustomTextFieldPage; +import atlantafx.sampler.page.components.DeckPanePage; +import atlantafx.sampler.page.components.InputGroupPage; +import atlantafx.sampler.page.components.MessagePage; +import atlantafx.sampler.page.components.ModalPanePage; +import atlantafx.sampler.page.components.PopoverPage; +import atlantafx.sampler.page.components.TilePage; +import atlantafx.sampler.page.components.ToggleSwitchPage; +import atlantafx.sampler.page.general.BBCodePage; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Set; import javafx.scene.Node; import org.jetbrains.annotations.Nullable; record Nav(String title, - @Nullable Node graphic, - @Nullable Class pageClass, - @Nullable List searchKeywords) { + @Nullable Node graphic, + @Nullable Class pageClass, + @Nullable List searchKeywords) { public static final Nav ROOT = new Nav("ROOT", null, null, null); + private static final Set> TAGGED_PAGES = Set.of( + BBCodePage.class, + BreadcrumbsPage.class, + CalendarPage.class, + CardPage.class, + CustomTextFieldPage.class, + DeckPanePage.class, + InputGroupPage.class, + MessagePage.class, + ModalPanePage.class, + PopoverPage.class, + TilePage.class, + ToggleSwitchPage.class + ); + public Nav { Objects.requireNonNull(title, "title"); searchKeywords = Objects.requireNonNullElse(searchKeywords, Collections.emptyList()); @@ -31,6 +59,10 @@ record Nav(String title, || (searchKeywords != null && searchKeywords.stream().anyMatch(keyword -> contains(keyword, filter))); } + public boolean isTagged() { + return pageClass != null && TAGGED_PAGES.contains(pageClass); + } + private boolean contains(String text, String filter) { return text.toLowerCase().contains(filter.toLowerCase()); } diff --git a/sampler/src/main/java/atlantafx/sampler/layout/NavTree.java b/sampler/src/main/java/atlantafx/sampler/layout/NavTree.java index 0b413b3..e53a221 100644 --- a/sampler/src/main/java/atlantafx/sampler/layout/NavTree.java +++ b/sampler/src/main/java/atlantafx/sampler/layout/NavTree.java @@ -5,6 +5,7 @@ package atlantafx.sampler.layout; import atlantafx.base.controls.Spacer; import atlantafx.base.theme.Tweaks; import atlantafx.sampler.page.Page; +import atlantafx.sampler.util.NodeUtils; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -12,6 +13,7 @@ import javafx.css.PseudoClass; import javafx.geometry.Pos; import javafx.scene.Cursor; import javafx.scene.Node; +import javafx.scene.control.ContentDisplay; import javafx.scene.control.Label; import javafx.scene.control.TreeCell; import javafx.scene.control.TreeItem; @@ -51,6 +53,7 @@ public final class NavTree extends TreeView