java.lang.Object
org.autogui.swing.GuiSwingPreferences
- All Implemented Interfaces:
GuiPreferences.PreferencesStoreChangeListener
public class GuiSwingPreferences
extends Object
implements GuiPreferences.PreferencesStoreChangeListener
a preferences manager.
GUI properties as preferences
- define a custom
GuiSwingPrefsSupports.PreferencesByJsonEntry
(orGuiSwingPrefsSupports.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 implementingGuiSwingPrefsSupports.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); } } }GuiSwingPrefsSupports.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; } }
- define a new visitor method in
GuiSwingPrefsApplyOptions
for applying prefs;default public void apply(PropUpdater updater, GuiPreferences prefs, P pane) { updater.prefs.applyTo(pane); }
this method also need to be overriden inGuiSwingPrefsEditor
for prefs settings pane.GuiSwingPrefsEditor.addToContentPaneIfFirst(GuiPreferences, Supplier)
can be usable.public void apply(PropUpdater updater, GuiPreferences prefs, P pane) { addToContentPaneIfFirst(prefs, PreferencesForX::new)); }
- the GUI component overrides
GuiSwingView.ValuePane.saveSwingPreferences(GuiPreferences)
andGuiSwingView.ValuePane.loadSwingPreferences(GuiPreferences, GuiSwingPrefsApplyOptions)
for bulk loading/saving.public void loadSwingPreferences(GuiPreferences p, GuiSwingPrefsApplyOptions options) { GuiSwingView.loadPreferencesDefault(this, p, options); updater.prefs.loadFrom(p.getDescendant(context)); updater.enabled = false; options.apply(updater, updaterprefs, this); updater.enabled = true; } public void saveSwingPreferences(GuiPreferences p) { GuiSwingView.savePreferencesDefault(this, p); updater.prefs.saveTo(p.getDescendant(context)); }
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
describe changes of default preferences storestatic class
static interface
static class
static class
the action for overwriting an existing prefs -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JTree
protected int[]
protected JTable
protected GuiSwingPreferences.PreferencesListModel
protected JPanel
protected JComponent
protected GuiMappingContext
protected GuiSwingPreferences.RootView
protected Map
<GuiPreferences, GuiSwingPrefsEditor> protected JComponent
protected SettingsWindow
-
Constructor Summary
ConstructorsConstructorDescriptionGuiSwingPreferences
(GuiMappingContext rootContext, JComponent rootComponent) -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
apply
(GuiPreferences preferences) void
void
createSettingsPane
(GuiPreferences prefs) void
void
void
void
void
void
void
protected void
getList()
getName
(GuiPreferences prefs) protected void
init()
protected JComponent
protected JComponent
initList()
protected void
void
protected void
protected void
initRunnerToSupports
(Component component) protected void
protected void
boolean
isEmpty
(GuiPreferences prefs) boolean
boolean
boolean
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()
void
storeChanged
(GuiPreferences prefs, String key, Object value) toSafeName
(String name) void
protected void
-
Field Details
-
mainPane
-
rootContext
-
rootPane
-
rootComponent
-
list
-
listModel
-
contentTree
-
settingsPane
-
prefsWindowUpdater
-
settingsWindow
-
lastSelection
protected int[] lastSelection -
settingsEditors
-
updater
-
-
Constructor Details
-
GuiSwingPreferences
-
GuiSwingPreferences
-
-
Method Details
-
setRootView
-
init
protected void init() -
initMainPane
protected void initMainPane() -
initList
-
initContentTree
-
initToolBar
protected void initToolBar() -
initSettingPrefs
protected void initSettingPrefs() -
show
-
setSettingsWindow
-
getRootContext
-
isEmpty
-
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() -
createSettingsPane
-
updateContentTree
public void updateContentTree() -
shutdown
public void shutdown() -
getLaunchPreferences
-
getSavedPreferencesList
-
getName
-
setupCheckBox
-
doNewPrefs
public void doNewPrefs() -
doUpdatePrefs
public void doUpdatePrefs() -
doDeletePrefs
public void doDeletePrefs() -
isSelectedPreferencesEditable
public boolean isSelectedPreferencesEditable() -
isSelectedPreferencesEditableAll
public boolean isSelectedPreferencesEditableAll() -
doSavePrefs
public void doSavePrefs() -
toSafeName
-
doLoadPrefs
public void doLoadPrefs() -
doApplyPrefs
public void doApplyPrefs() -
apply
-
doDuplicatePrefs
public void doDuplicatePrefs() -
initRunner
public void initRunner() -
initRunnerToSupports
-
getUpdater
-
getUpdateRunner
-
initRunnerPrefsDefault
protected void initRunnerPrefsDefault() -
storeChanged
- Specified by:
storeChanged
in interfaceGuiPreferences.PreferencesStoreChangeListener
-
runPreferencesUpdate
-
flushRootPrefs
protected void flushRootPrefs() -
updateDefaultDisplay
protected void updateDefaultDisplay()
-