MAGICSYNCHRONIZER Creates an object to synchronize a set of properties.
ms = MagicSynchronizer( callback, ...
[ 'EXE' ], ...
[ 'IN', obj, prop, [ prop2, [...] ], [ obj2, ... ] ], ...
[ 'OUT', obj, prop, [ prop2, [...] ], [ obj2, ... ] ], ...
[ 'DEP', obj, [ obj2 ... ] ], ...
[ 'CHECKIN', check ], ...
[ 'NAME', name ] );
creates a new synchronizer
The callback is a function handle, which doesn't take any argument and doesn't return any value. This callback will be called when any 'input' properties has been changed ('IN' set).
'DEP' is an optionnal set, and can be use to link the life cycle of the synchronizer with another objects.
'EXE' is an optional flag. When it's given, the callback is called once in the constructor.
'CHECKIN' is an optional boolean (true per default). When it's false, the synchronizer don't check if the input has been changed. You can change directly this value when the synchronizer is created whith the property 'CheckIn'.
'NAME' is an optionnal argument, only useful for debugging.
If the string 'copy' is given instead the callback, a default callback which copy "out" properties to "in" emplacements is used.
When a synchronizer is created, it searchs automatically from what synchronizer it depends, and what synchronizers are depending from it. So, when a synchronizer is launch, it launchs its children too.
You can't launch a specific synchronizer, but you can notify you have changed some property values, and the synchronizers which are listening theses properties will be lauch. To notify some changements, you have to use the class function MagicSynchronizer.synchronize:
MagicSynchronizer.synchronize( [obj] | [obj,'prop',['prop2',...]], ... );
Synchronizers save the last values of properties: a synchronizer calls the callback only if at least one input property is modified.
The callback can interrupt the progress (e.g. the user has clicked on the famous "cancel" button), with throwing a MagicSynchronizer.interruptionError error. The goal of synchronizer is to keep a homogeous state beetwen all given properties. So, when this error appends, the inputs properties are restored to the last "stable" version, also the properties of the synchronizer's parents. If any else error appends, the error is immediatly rethrown: the properties are not synchronized.
Sometimes, during the developpment of a programm, you need to delete every synchronizers. To do that:
Of course, absolutly all synchronizer will be destructed. This command can help a "clear classes".
The class DemoSynchronizers provides a demonstration. The gui (and only the gui of that class) needs MagicListener and Wrapper:
Benoit Charles (2023). MagicSynchronizer (https://www.mathworks.com/matlabcentral/fileexchange/34828-magicsynchronizer), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!