Package com.calebleavell.jatui.templates
Class NumberedModuleSelector
java.lang.Object
com.calebleavell.jatui.modules.TUIModule.Builder<NumberedModuleSelector>
com.calebleavell.jatui.modules.ModuleTemplate<NumberedModuleSelector>
com.calebleavell.jatui.templates.NumberedModuleSelector
- All Implemented Interfaces:
DirectedGraphNode<TUIModule.Property,TUIModule.Builder<?>, NumberedModuleSelector>
Handles navigating to a module based on a user's decision.
Example usage:
Example usage:
ApplicationModule app = ApplicationModule.builder("app").build();
NumberedModuleSelector selector = NumberedModuleSelector.builder("selector", app)
.addModule("Display Hello", TextModule.builder("display-hello", "Hello"))
.addModule("Display World", TextModule.builder("display-world", "World"));
app.setHome(selector);
app.run();
Output:
[1] Display Hello [2] Display World Your choice: 1 Hello Exiting...
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.calebleavell.jatui.core.DirectedGraphNode
DirectedGraphNode.PropertyUpdateFlag -
Field Summary
Fields inherited from class com.calebleavell.jatui.modules.ModuleTemplate
mainFields inherited from class com.calebleavell.jatui.modules.TUIModule.Builder
ansi, application, children, enableAnsi, logger, name, printStream, propertyUpdateFlags, scanner, type, usedNames -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedNumberedModuleSelector(String name, ApplicationModule app) Constructor forNumberedModuleSelector. -
Method Summary
Modifier and TypeMethodDescriptionaddModule(TUIModule.Builder<?> module) Adds a module option to the selector.Adds a module option to the selector.addModule(String displayText, TUIModule.Builder<?> module) Adds a module option to the selector.Adds a module option to the selector.static NumberedModuleSelectorbuilder(String name, ApplicationModule app) Constructs a newNumberedModuleSelectorbuilder.protected NumberedModuleSelectorGets a fresh instance of this type of Builder.voidshallowCopy(NumberedModuleSelector original) Copies theNameOrModuleobjects and theNumberedListobject, and delegates toTUIModule.Builder.shallowCopy(TUIModule.Builder).booleanshallowStructuralEquals(NumberedModuleSelector first, NumberedModuleSelector second) Checks equality for properties given by the builder.Methods inherited from class com.calebleavell.jatui.modules.ModuleTemplate
build, deepCopyMethods inherited from class com.calebleavell.jatui.modules.TUIModule.Builder
addChild, addChild, addChildren, addChildren, appendStyle, application, clearChildren, deepCopy, enableAnsi, getAnsi, getAnsiEnabled, getApplication, getChild, getChild, getChildren, getCopy, getDeepCopy, getName, getPrintStream, getPropertyUpdateFlags, getScanner, getType, lockProperty, name, prependStyle, prependToName, printStream, scanner, self, structuralEquals, style, toString, unlockProperty, updateFlag, updatePropertiesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.calebleavell.jatui.core.DirectedGraphNode
abstractSelf, containsNullNode, containsNullNode, dfs, dfs, forEach, forEachChild, structuralEquals, structuralEquals, updateProperty, updateProperty
-
Constructor Details
-
NumberedModuleSelector
Constructor forNumberedModuleSelector.- Parameters:
name- The name of the module.app- The application to work with. CallsTUIModule.Builder.application(ApplicationModule).
-
NumberedModuleSelector
protected NumberedModuleSelector()
-
-
Method Details
-
builder
Constructs a newNumberedModuleSelectorbuilder.- Parameters:
name- The name of the builder.app- TheApplicationModulethis module will be tied to.- Returns:
- The new builder.
-
createInstance
Gets a fresh instance of this type of Builder. Note, this is intended only for copying utility and may have unknown consequences if used in other ways.- Specified by:
createInstancein classTUIModule.Builder<NumberedModuleSelector>- Returns:
- A fresh, empty instance.
-
shallowCopy
Copies theNameOrModuleobjects and theNumberedListobject, and delegates toTUIModule.Builder.shallowCopy(TUIModule.Builder).- Overrides:
shallowCopyin classTUIModule.Builder<NumberedModuleSelector>- Parameters:
original- The builder to copy from.
-
addModule
Adds a module option to the selector. AddsdisplayTextviaNumberedList.addListText(String).- Parameters:
displayText- The text to display (e.g., if displayText="myText" "[1] myText).moduleName- The name of the module the user may navigate to that is connected theApplicationModuletied to this module (via eitherApplicationModule.setHome(TUIModule.Builder)orTUIModule.Builder.addChild(TUIModule.Builder)). The module doesn't have to be a direct child.- Returns:
- self
-
addModule
Adds a module option to the selector. AddsdisplayTextviaNumberedList.addListText(String).- Parameters:
displayText- The text to display (e.g., if displayText="myText" "[1] myText).module- TheTUIModule.Builderthe user may navigate to.- Returns:
- self
-
addModule
Adds a module option to the selector. Uses the name of the module as the displayed list option. e.g., if the name of the module is "myModule", the option could be "[1] myModule."- Parameters:
moduleName- The name of the module the user may navigate to that is connected theApplicationModuletied to this module (via eitherApplicationModule.setHome(TUIModule.Builder)orTUIModule.Builder.addChild(TUIModule.Builder)). The module doesn't have to be a direct child.- Returns:
- self
-
addModule
Adds a module option to the selector. Uses the name of the module as the displayed list option. e.g., if the name of the module is "myModule", the option could be "[1] myModule."- Parameters:
module- TheTUIModule.Builderthe user may navigate to.- Returns:
- self
-
shallowStructuralEquals
Checks equality for properties given by the builder. ForNumberedModuleSelector, this includesmodules, as well as other requirements provided byTUIModule.Builder.shallowStructuralEquals(TUIModule.Builder, TUIModule.Builder).- Specified by:
shallowStructuralEqualsin interfaceDirectedGraphNode<TUIModule.Property,TUIModule.Builder<?>, NumberedModuleSelector> - Overrides:
shallowStructuralEqualsin classTUIModule.Builder<NumberedModuleSelector>- Parameters:
first- The first TUIModule to comparesecond- The second TUIModule to compare- Returns:
trueiffirstandsecondare equal according to builder-provided properties
-