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.PreferencesUpdateSupportclass 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
GuiSwingPrefsApplyOptionsfor applying prefs;default public void apply(PropUpdater updater, GuiPreferences prefs, P pane) { updater.prefs.applyTo(pane); }this method also need to be overriden inGuiSwingPrefsEditorfor 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 classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classdescribe changes of default preferences storestatic classstatic interfacestatic classstatic classthe action for overwriting an existing prefs -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JTreeprotected int[]protected JTableprotected GuiSwingPreferences.PreferencesListModelprotected JPanelprotected JComponentprotected GuiMappingContextprotected GuiSwingPreferences.RootViewprotected Map<GuiPreferences, GuiSwingPrefsEditor> protected JComponentprotected SettingsWindow -
Constructor Summary
ConstructorsConstructorDescriptionGuiSwingPreferences(GuiMappingContext rootContext, JComponent rootComponent) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidapply(GuiPreferences preferences) voidvoidcreateSettingsPane(GuiPreferences prefs) voidvoidvoidvoidvoidvoidvoidprotected voidgetList()getName(GuiPreferences prefs) protected voidinit()protected JComponentprotected JComponentinitList()protected voidvoidprotected voidprotected voidinitRunnerToSupports(Component component) protected voidprotected voidbooleanisEmpty(GuiPreferences prefs) booleanbooleanbooleanvoidvoidvoidvoidsavePreferences(GuiPreferences prefs) voidsetRootView(GuiSwingPreferences.RootView rootPane) voidsetSettingsWindow(SettingsWindow settingsWindow) static voidsetupCheckBox(JCheckBox box) voidshow(JComponent sender) voidvoidshutdown()voidstoreChanged(GuiPreferences prefs, String key, Object value) toSafeName(String name) voidprotected 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:
storeChangedin interfaceGuiPreferences.PreferencesStoreChangeListener
-
runPreferencesUpdate
-
flushRootPrefs
protected void flushRootPrefs() -
updateDefaultDisplay
protected void updateDefaultDisplay()
-