java.lang.Object
org.autogui.swing.GuiSwingPreferences
a preferences manager.
GUI properties as preferences
- define a custom
GuiSwingPreferences.PreferencesByJsonEntry
(orGuiSwingPreferences.Preferences
).class PreferencesForX implements PreferencesByJsonEntry { protected int prop; //a GUI property public void applyTo(P guiComp) { //the method for setting the property of the component guiComp.setProp(prop); } public void set(P guiComp) { //from the component to the prefs prop = guiComp.getProp(); } public String getKey() { return "$x"; } //the entry key public Object toJson() { Map m = new HashMap(); m.put("p", prop); return m; } //to a JSON entry public void setJson(Object j) { if (j != null && j instanceof Map) { prop = (Integer) ((Map) j).get("p"); } } }
- a GUI component defines a listener for incremental updating of properties
class PropUpdater implements XListener { GuiMappingContext context; boolean enabled = true; Consumer<
and the GUI component sets up the listener with implementingGuiSwingPreferences.PreferencesUpdateEvent
> updater; PreferencesForX prefs = new PreferencesForX(); void changed(Event e) { //suppose an event handler if (enabled) { prefs.set(e.getComponent()); updater.accept(new PreferencesUpdateEvent(context, prefs); } } }GuiSwingPreferences.PreferencesUpdateSupport
class P implements ValuePane, PreferencesUpdateSupport { PropUpdater updater; P(GuiMappingContext c) { ... updater = new PropUpdater(c); addXLister(updater); } public void setPreferencesUpdater(Consumer<PreferencesUpdateEvent> u) { updater.updater = u; } }
- the GUI component overrides
GuiSwingView.ValuePane.saveSwingPreferences(GuiPreferences)
andGuiSwingView.ValuePane.loadSwingPreferences(GuiPreferences)
for bulk loading/saving.public void loadSwingPreferences(GuiPreferences p) { GuiSwingView.loadPreferencesDefault(this, p); updater.prefs.loadFrom(p.getDescendant(context)); updater.enabled = false; updater.prefs.applyTo(this); updater.enabled = true; } public void saveSwingPreferences(GuiPreferences p) { GuiSwingView.savePreferencesDefault(this, p); updater.prefs.saveTo(p.getDescendant(context)); }
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
static class
static class
static class
static interface
static interface
static class
static class
static class
static class
static class
static class
static class
static class
static interface
partial updaterstatic class
static interface
options at prefs loadingstatic class
the default impl.static class
cell-renderer for prefs-treestatic class
tree-model value for prefs-treestatic class
static interface
static class
static class
-
Field Summary
Modifier and TypeFieldDescriptiondefault options at prefs loading: non-init, no skippingprotected JEditorPane
Deprecated.protected JTree
protected int[]
protected JTable
protected GuiSwingPreferences.PreferencesListModel
protected JPanel
protected JComponent
protected GuiMappingContext
protected GuiSwingPreferences.RootView
protected SettingsWindow
-
Constructor Summary
ConstructorDescriptionGuiSwingPreferences
(GuiMappingContext rootContext, JComponent rootComponent) -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
void
void
expandTreeAll
(DefaultTreeModel treeModel, TreeNode n) getList()
getName
(GuiPreferences prefs) protected void
init()
void
protected void
initRunnerToSupports
(Component component) boolean
makeTreeNode
(List<GuiPreferences> list) makeTreeNode
(GuiPreferences prefs) void
void
void
void
savePreferences
(GuiPreferences prefs) void
setRootView
(GuiSwingPreferences.RootView rootPane) void
setSettingsWindow
(SettingsWindow settingsWindow) static void
setupCheckBox
(JCheckBox box) void
show
(JComponent sender) void
void
shutdown()
-
Field Details
-
mainPane
-
rootContext
-
rootPane
-
rootComponent
-
list
-
listModel
-
contentTextPane
Deprecated. -
contentTree
-
prefsWindowUpdater
-
settingsWindow
-
lastSelection
protected int[] lastSelection -
updater
-
APPLY_OPTIONS_DEFAULT
default options at prefs loading: non-init, no skipping- Since:
- 1.4
-
-
Constructor Details
-
GuiSwingPreferences
-
GuiSwingPreferences
-
-
Method Details
-
setRootView
-
init
protected void init() -
show
-
setSettingsWindow
-
getRootContext
-
reloadList
public void reloadList() -
getSelectedSavedPreferencesList
-
getSelectedSavedPreferences
-
getList
-
addSelectionListener
-
isSelectionEmpty
public boolean isSelectionEmpty() -
getMainPane
-
applyPreferences
public void applyPreferences() -
applyPreferences
- Parameters:
options
- options for applying- Since:
- 1.4
-
savePreferences
-
getPrefsWindowUpdater
-
restoreSelection
public void restoreSelection() -
showSelectedPrefs
public void showSelectedPrefs() -
expandTreeAll
- Parameters:
treeModel
- a modeln
- a node in the model- Since:
- 1.3
-
makeTreeNode
- Parameters:
list
- list of prefs- Returns:
- tree-model of list
- Since:
- 1.3
-
makeTreeNode
- Parameters:
prefs
- a prefs- Returns:
- the node for prefs
- Since:
- 1.3
-
shutdown
public void shutdown() -
getLaunchPreferences
-
getSavedPreferencesList
-
getName
-
setupCheckBox
-
initRunner
public void initRunner() -
initRunnerToSupports
-
getUpdater
-
getUpdateRunner
-
runPreferencesUpdate
-