java.lang.Object
org.autogui.base.mapping.GuiPreferencesLoader
the class for manually setting preferences to target objects
GuiPreferencesLoader.get().apply(obj); //setting properties from default saved prefs ("/pack/to/Cls/$default")
GuiPreferencesLoader.get().withPrefsGetterByNameEquals("p").apply(obj); //setting properties from saved prefs as "p" //("/pack/to/Cls/$saved/$N" and "$name" is "p")
var restArgs = GuiPreferencesLoader.get().parseArgs(obj, Arrays.asList(args)); //e.g. args={"-l", "p"} then, load and apply prefs "p" to obj
- Since:
- 1.4
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map
<GuiPreferencesLoader.PrefsLoaderCommandArg, List<String>> protected GuiMappingContext
protected Function
<GuiPreferences, GuiPreferences> protected GuiTypeBuilder
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply()
applies the current context toapplyForContext(GuiMappingContext)
loading specified saved prefs to the obj The prefs can be selected bywithPrefsGetterDefault()
(default) orwithPrefsGetterByNameEquals(String)
applyForContext
(GuiMappingContext context) takes prefs from the context and selects a prefs by the getter set bywithPrefsGetter(Function)
, and callsload(GuiPreferences)
with the prefsstatic GuiPreferences
findSavedPrefsByName
(GuiPreferences rootPrefs, Predicate<String> name) static GuiPreferences
findSavedPrefsDefault
(GuiPreferences rootPrefs) static GuiPreferencesLoader
get()
static String
getPrefsName
(GuiPreferences savedPrefs) static List
<GuiPreferences> getSavedPrefs
(GuiMappingContext context) static List
<GuiPreferences> void
handleError
(Throwable error, GuiPreferences prefs) load
(GuiPreferences prefs) load
(GuiPreferences prefs, GuiReprValue.ObjectSpecifier specifier) sets current saved value taken from the prefs to the properties of the source object of the context.consume head args forGuiPreferencesLoader.PrefsLoaderCommandArg
and do the option.void
void
runHelp()
println(Object)
help messages ofGuiPreferencesLoader.PrefsLoaderCommandArg
void
get the prefs andprintln(Object)
JSON source of the prefsvoid
set prefs getter with arg andapply()
void
println(Object)
names of saved prefs for current contexttakeSavedPrefs
(GuiMappingContext context) sets command line args forparseArgs(List)
.withContext
(GuiMappingContext context) creates aGuiMappingContext
for the given object, withGuiTypeBuilder
previously set bywithTypeBuilder(GuiTypeBuilder)
withPrefsGetter
(Function<GuiPreferences, GuiPreferences> prefsGetter) sets the prefs selector that takes the root prefs and returns a saved preferences; typically, it takes an element ofGuiPreferences.getSavedStoreListAsRoot()
withPrefsGetter(Function)
withfindSavedPrefsByName(GuiPreferences, Predicate)
for selecting named prefswithPrefsGetter(Function)
withfindSavedPrefsDefault(GuiPreferences)
for selecting default prefswithTypeBuilder
(GuiTypeBuilder typeBuilder) set the type-builder toGuiTypeBuilder.GuiTypeBuilderRelaxed
.
-
Field Details
-
typeBuilder
-
prefsGetter
-
context
-
argNames
-
-
Constructor Details
-
GuiPreferencesLoader
public GuiPreferencesLoader()
-
-
Method Details
-
get
-
withTypeBuilder
-
withTypeBuilderRelaxed
set the type-builder toGuiTypeBuilder.GuiTypeBuilderRelaxed
. This is required for taking prefs of the app launched byAutoGuiShell.showLive(...).
- Returns:
- this
-
withPrefsGetter
sets the prefs selector that takes the root prefs and returns a saved preferences; typically, it takes an element ofGuiPreferences.getSavedStoreListAsRoot()
- Parameters:
prefsGetter
- the selector function- Returns:
- this
-
withPrefsGetterByNameEquals
withPrefsGetter(Function)
withfindSavedPrefsByName(GuiPreferences, Predicate)
for selecting named prefs- Parameters:
name
- the name compared to the "$name" value- Returns:
- this
-
withPrefsGetterDefault
withPrefsGetter(Function)
withfindSavedPrefsDefault(GuiPreferences)
for selecting default prefs- Returns:
- this
-
withContextForObject
creates aGuiMappingContext
for the given object, withGuiTypeBuilder
previously set bywithTypeBuilder(GuiTypeBuilder)
- Parameters:
obj
- the target object of the creating context- Returns:
- this
-
withContext
-
getSavedPrefs
-
getSavedPrefsWithDefault
-
getSavedPrefsNames
-
getSavedPrefs
-
getSavedPrefsWithDefault
-
apply
loading specified saved prefs to the obj The prefs can be selected bywithPrefsGetterDefault()
(default) orwithPrefsGetterByNameEquals(String)
- Parameters:
obj
- the context target supplied bywithContext(GuiMappingContext)
- Returns:
apply()
-
apply
applies the current context toapplyForContext(GuiMappingContext)
- Returns:
- the returned object by
applyForContext(GuiMappingContext)
-
applyForContext
takes prefs from the context and selects a prefs by the getter set bywithPrefsGetter(Function)
, and callsload(GuiPreferences)
with the prefs- Parameters:
context
- the context for prefs- Returns:
- the returned object by load
-
takeSavedPrefs
-
takeSavedPrefs
-
findSavedPrefsByName
-
getPrefsName
-
findSavedPrefsDefault
-
load
- Parameters:
prefs
- the source prefs- Returns:
- the current source value of the context
-
load
sets current saved value taken from the prefs to the properties of the source object of the context. It takes the context from prefsGuiPreferences.getContext()
- Parameters:
prefs
- the source prefsspecifier
- the specifier- Returns:
- context's
GuiMappingContext.getSource()
value or null
-
handleError
-
withArgNames
public GuiPreferencesLoader withArgNames(Map<GuiPreferencesLoader.PrefsLoaderCommandArg, List<String>> argNames) sets command line args forparseArgs(List)
. e.g..withArgNames(Map.of( LoadByName, List.of("-L", "--load"), //replace existing command options Help, List.of())) //no values: disable the option //for unspecified keys, default args are used.
- Parameters:
argNames
- the maps for customizing args- Returns:
- this
-
parseArgs
- Parameters:
obj
- the target objargs
- command args- Returns:
- rest of consumed args
- See Also:
-
parseArgs
- Parameters:
obj
- the target obj for callingwithContext(GuiMappingContext)
args
- command args- Returns:
- rest of consumed args
- See Also:
-
parseArgs
consume head args forGuiPreferencesLoader.PrefsLoaderCommandArg
and do the option.GuiPreferencesLoader.PrefsLoaderCommandArg.LoadByName
:-l <name>
. consume 2 elements andrunLoad(String)
GuiPreferencesLoader.PrefsLoaderCommandArg.ShowNames
:-s
. consume 1 element andrunShowNames()
GuiPreferencesLoader.PrefsLoaderCommandArg.ShowJsonByName
:-j <name>
. consume 2 elements andrunJson(String)
GuiPreferencesLoader.PrefsLoaderCommandArg.Help
:-h
. checks the top element but not consume the -h, andrunHelp()
withContext(GuiMappingContext)
- Parameters:
args
- the consumed args- Returns:
- the rest of consumed args
-
runLoad
set prefs getter with arg andapply()
- Parameters:
arg
- the name forwithPrefsGetterByNameEquals(String)
or "." forwithPrefsGetterDefault()
-
runShowNames
public void runShowNames()println(Object)
names of saved prefs for current context -
runJson
get the prefs andprintln(Object)
JSON source of the prefs- Parameters:
arg
- the name forwithPrefsGetterByNameEquals(String)
or "." forwithPrefsGetterDefault()
-
runHelp
public void runHelp()println(Object)
help messages ofGuiPreferencesLoader.PrefsLoaderCommandArg
-
println
-