From a267667c8924154743771e02e53f7729660ac922 Mon Sep 17 00:00:00 2001 From: Smithor Date: Fri, 13 Feb 2026 09:52:10 -0700 Subject: [PATCH] Abstract version of ViewOwner that makes it easier to remember which methods are the essential ones. Documentation change. Provided an actually usable implementation of the idea, complete with default methods that reference the original ViewOwner. @apiNote is not supported by Gradle Javadoc plugin. Added a CustomViewOwner class that makes ViewOwner controls explicit. Otherwise harmonious with existing ViewOwner. --- src/snap/view/CustomViewOwner.java | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/snap/view/CustomViewOwner.java diff --git a/src/snap/view/CustomViewOwner.java b/src/snap/view/CustomViewOwner.java new file mode 100644 index 00000000..fdcc7967 --- /dev/null +++ b/src/snap/view/CustomViewOwner.java @@ -0,0 +1,62 @@ +package snap.view; + +/** + * Helper class to create custom ViewOwners with novel interpretations. + */ +public abstract class CustomViewOwner extends ViewOwner { + + /** + * Creates the top level view for this owner. + *

+ * API Note: If you want the vanilla interaction of this class, return {@code default_createUI();} + */ + @Override + abstract protected View createUI(); + + /** + * Initializes the UI panel. + *

+ * API Note: If you want the vanilla interaction of this class, return {@code default_initUI();} + */ + @Override + abstract protected void initUI(); + + /** + * Reset UI controls. + *

+ * API Note: If you want the vanilla interaction of this class, return {@code default_resetUI();} + */ + @Override + abstract protected void resetUI(); + + /** + * Respond to UI controls. + *

+ * API Note: If you want the vanilla interaction of this class, return {@code default_respondUI(ViewEvent);} + * @param anEvent Any event that has been caught by this ViewOwner. + */ + @Override + abstract protected void respondUI(ViewEvent anEvent); + + /** + * Default implementation of {@link ViewOwner#createUI()} + * @return View loaded from snp file of the same name as the class. + */ + final protected View default_createUI() {return super.createUI();} + + /** + * Default implementation of {@link ViewOwner#initUI()} + */ + final protected void default_initUI() {super.initUI();} + + /** + * Default implementation of {@link ViewOwner#resetUI()} + */ + final protected void default_resetUI() {super.resetUI();} + + /** + * Default implementation of {@link ViewOwner#respondUI(ViewEvent)} + * @param anEvent An event which has been captured by the view. + */ + final protected void default_respondUI(ViewEvent anEvent) {super.respondUI(anEvent);} +}