From cf2f46a4e0e3b729c7ba6a206017dc4ac844a8fe Mon Sep 17 00:00:00 2001 From: mkpaz Date: Fri, 26 May 2023 21:43:42 +0400 Subject: [PATCH] Make small improvements to Sampler - Support internal links - Hide disable switch in some examples --- .../atlantafx/sampler/event/NavEvent.java | 25 ++++++++++++ .../atlantafx/sampler/layout/MainModel.java | 6 +++ .../java/atlantafx/sampler/layout/Nav.java | 38 +++++++++++++++++-- .../atlantafx/sampler/layout/NavTree.java | 11 +++++- .../java/atlantafx/sampler/page/Page.java | 25 +++++++++--- .../page/components/AnimationsPage.java | 2 +- .../sampler/page/components/DialogPage.java | 30 ++++++++++++--- .../sampler/page/components/MessagePage.java | 5 ++- .../page/components/ModalPanePage.java | 35 +++++++++++++---- .../sampler/page/components/PopoverPage.java | 10 ++++- .../components/ProgressIndicatorPage.java | 5 ++- .../sampler/page/components/TilePage.java | 6 +-- .../sampler/page/components/TooltipPage.java | 10 ++++- .../sampler/page/general/TypographyPage.java | 9 +++-- .../assets/styles/scss/layout/_sidebar.scss | 9 ++++- 15 files changed, 188 insertions(+), 38 deletions(-) create mode 100644 sampler/src/main/java/atlantafx/sampler/event/NavEvent.java 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