Code covered by the BSD License  

Highlights from
MagicSynchronizer

from MagicSynchronizer by Benoit Charles
MagicSynchronizer creates an object to synchronize a set of properties.

DemoSynchronizers
% DEMOSYNCHRONIZERS is a class demo for MagicSynchronizer.
%
% The gui (and only the gui) needs MagicListener and Wrappers:
%  http://www.mathworks.fr/matlabcentral/fileexchange/34606
%  http://www.mathworks.fr/matlabcentral/fileexchange/34728
%  

classdef DemoSynchronizers < handle
	
	%% ### PROPERTIES
	
	properties
		hFig = [];
	end
	
	properties( SetObservable )
		
		% ### A
		% IN
		inputA = 0;
		% OUT
		outputA = 10;
		
		% ### B
		% IN
		inputB = 0;
		% OUT
		outputB = 0;
		
		% ### C
		% IN
		inputC = 0;
		% OUT
		outputC = 0;
		
	end
	
	%% ### CONSTRUCTOR
	
	methods
		
		function this = DemoSynchronizers()
			
			%% Synchronizers
			
			% Run A if inputA is modified
			MagicSynchronizer( @() this.AlgoA(), ...
				'IN', this, 'inputA', ...
				'OUT', this, 'outputA' );
			
			% Run B if inputB or outputA are modified
			MagicSynchronizer( @() this.AlgoB(), 'EXE', ...
				'IN', this, 'inputB', 'outputA', ...
				'OUT', this, 'outputB' );
			
			% Run C if inputC or outputA are modified
			MagicSynchronizer( @() this.AlgoC(), 'EXE', ...
				'IN', this, 'inputC', 'outputA', ...
				'OUT', this, 'outputC' );
			
			% Run D if outputB or outputC are modified
			MagicSynchronizer( @() this.AlgoD(), 'EXE', ...
				'IN', this, 'outputB', 'outputC' );
			
			% % What appends wherever you have a loop?
			% MagicSynchronize( 'copy', ...
			% 	'IN', this, 'outputC', ...
			% 	'OUT', this, 'inputA' );
			
			%% GUI
			
			hf = FigureWrapper( 'Color', [1 1 1]*240/255 ); this.hFig = hf;
			MagicListener( hf, 'DeleteEvent', @(H,E)delete( this ), this );
			
			props = { ...
				'Parent', hf, ...
				'Units', 'normalized' }; ...
			editProps = [ props, 'Style', 'edit' ];
			
			nbComp = 7; nbSpace = 8;
			spaceHeight = 1/(nbComp+nbSpace);
			compHeight = spaceHeight;
			currHeight = 1 - spaceHeight - compHeight;
			
			function displayAlgo( letter, title )
				
				inputField = sprintf( 'input%s', letter );
				outputField = sprintf( 'output%s', letter );
				
				MagicTextWrapper( props{:}, ...
					'Position', [ 0.1 currHeight 0.8 compHeight ], ...
					'String', title, ...
					'HorizontalAlignment', 'center' );
				currHeight = currHeight - spaceHeight - compHeight;
				ControlWrapper( editProps{:}, ...
					'Position', [ 0.1 currHeight 0.35 compHeight ], ...
					'String', { this, inputField, 'string<->double' } );
				MagicTextWrapper( props{:}, ...
					'Position', [ 0.55 currHeight 0.35 compHeight ], ...
					'String', { this, outputField, 'string<->double' } );
				currHeight = currHeight - spaceHeight - compHeight;
				
			end
			
			displayAlgo( 'A', 'Algo A (+10)' );
			displayAlgo( 'B', 'Algo B (+A)' );
			displayAlgo( 'C', 'Algo C (*A)' );
			
			apply = ControlWrapper( props{:}, ...
				'Style', 'pushbutton', ...
				'Position', [ 0.1 currHeight 0.8 compHeight ], ...
				'String', 'Apply' );
			MagicListener( apply, 'ActionEvent', @(H,E) MagicSynchronizer.synchronize( this ) );
			
		end
		
		%% Destructor
		
		function delete( this )
			if isvalid( this.hFig )
				delete( this.hFig );
			end
		end
		
	end
	
	%% ### ALGO
	
	methods
		
		function AlgoA( this )
			fprintf( '[RUN A]' );
			this.outputA = 10 + this.inputA;
		end
		
		function AlgoB( this )
			fprintf( '[RUN B]' );
			this.outputB = this.inputB + this.outputA;
		end
		
		function AlgoC( this )
			fprintf( '[RUN C]' );
			this.outputC = this.inputC * this.outputA;
		end
		
		function AlgoD( this )
			fprintf( '\n[%s] Value B:%g\tValue C:%g\n', datestr( now, 13 ), this.outputB, this.outputC );
		end
		
	end
	
end

Contact us