Code covered by the BSD License  

Highlights from
Graphical Wrappers

from Graphical Wrappers by Benoit Charles
Wrappers improve Matlab graphical components.

ControlWrapper
% CONTROLWRAPPER is an object wrappering an uicontrol.
%
%	The internal uicontrol handle can be access by the property hcontrol.
%
%	The properties String2 can be used to have the current value of the
%	property String, while the uicontrol still have the focus. The
%	utilisation of that property need findjobj:
%			http://www.mathworks.fr/matlabcentral/fileexchange/14317
%
%	The callbacks are replaced by events:
%		Callback		->	ActionEvent
%		KeyPressFcn		->	KeyPressEvent
%		ButtonDownFcn	->	ButtonDownEvent
%		DeleteFcn		->	DeleteEvent
% 
%	See also: GraphicalHandleWrapper.
%

classdef ControlWrapper < GraphicalHandleWrapper
	
	%% UIControl handle
	
	properties( Dependent, SetAccess = private )
		hcontrol
	end
	
	properties( SetAccess = private, Hidden )
		jHandle = [];
	end
	
	methods
		
		function hc = get.hcontrol( this )
			hc = this.internalHandle;
		end
		
	end
	
	%% Public fields
	
	properties( Dependent, SetObservable, GetObservable )
		BackgroundColor
		CData
		Enable
		Extent
		FontAngle
		FontName
		FontSize
		FontUnits
		FontWeight
		ForegroundColor
		HorizontalAlignment
		ListboxTop
		Max
		Min
		Position
		String
		Style
		SliderStep
		TooltipString
		Units
		Value
		
		BeingDeleted
		Children
		Clipping
		BusyAction
		HandleVisibility
		HitTest
		Interruptible
		Parent
		Selected
		SelectionHighlight
		Tag
		Type
		UIContextMenu
		UserData
		Visible
	end
	
	properties( Dependent, SetObservable, GetObservable, Hidden )
		
		String2
		
	end
	
	%% Get / Set
	
	methods
		
		% BackgroundColor
		function set.BackgroundColor( this, val )
			this.set( 'BackgroundColor', val );
		end
		function val = get.BackgroundColor( this )
			val = this.get( 'BackgroundColor' );
		end
		
		% CData
		function set.CData( this, val )
			this.set( 'CData', val );
		end
		function val = get.CData( this )
			val = this.get( 'CData' );
		end
		
		% Enable
		function set.Enable( this, val )
			this.set( 'Enable', val );
		end
		function val = get.Enable( this )
			val = this.get( 'Enable' );
		end
		
		% Extent
		function set.Extent( this, val )
			this.set( 'Extent', val );
		end
		function val = get.Extent( this )
			val = this.get( 'Extent' );
		end
		
		% FontAngle
		function set.FontAngle( this, val )
			this.set( 'FontAngle', val );
		end
		function val = get.FontAngle( this )
			val = this.get( 'FontAngle' );
		end
		
		% FontName
		function set.FontName( this, val )
			this.set( 'FontName', val );
		end
		function val = get.FontName( this )
			val = this.get( 'FontName' );
		end
		
		% FontSize
		function set.FontSize( this, val )
			this.set( 'FontSize', val );
		end
		function val = get.FontSize( this )
			val = this.get( 'FontSize' );
		end
		
		% FontUnits
		function set.FontUnits( this, val )
			this.set( 'FontUnits', val );
		end
		function val = get.FontUnits( this )
			val = this.get( 'FontUnits' );
		end
		
		% FontWeight
		function set.FontWeight( this, val )
			this.set( 'FontWeight', val );
		end
		function val = get.FontWeight( this )
			val = this.get( 'FontWeight' );
		end
		
		% ForegroundColor
		function set.ForegroundColor( this, val )
			this.set( 'ForegroundColor', val );
		end
		function val = get.ForegroundColor( this )
			val = this.get( 'ForegroundColor' );
		end
		
		% HorizontalAlignment
		function set.HorizontalAlignment( this, val )
			this.set( 'HorizontalAlignment', val );
		end
		function val = get.HorizontalAlignment( this )
			val = this.get( 'HorizontalAlignment' );
		end
		
		% ListboxTop
		function set.ListboxTop( this, val )
			this.set( 'ListboxTop', val );
		end
		function val = get.ListboxTop( this )
			val = this.get( 'ListboxTop' );
		end
		
		% Max
		function set.Max( this, val )
			this.set( 'Max', val );
		end
		function val = get.Max( this )
			val = this.get( 'Max' );
		end
		
		% Min
		function set.Min( this, val )
			this.set( 'Min', val );
		end
		function val = get.Min( this )
			val = this.get( 'Min' );
		end
		
		% Position
		function set.Position( this, val )
			this.set( 'Position', val );
		end
		function val = get.Position( this )
			val = this.get( 'Position' );
		end
		
		% String
		function set.String( this, val )
			this.set( 'String', val );
		end
		function val = get.String( this )
			val = this.get( 'String' );
		end
		
		% Style
		function set.Style( this, val )
			this.set( 'Style', val );
		end
		function val = get.Style( this )
			val = this.get( 'Style' );
		end
		
		% SliderStep
		function set.SliderStep( this, val )
			this.set( 'SliderStep', val );
		end
		function val = get.SliderStep( this )
			val = this.get( 'SliderStep' );
		end
		
		% TooltipString
		function set.TooltipString( this, val )
			this.set( 'TooltipString', val );
		end
		function val = get.TooltipString( this )
			val = this.get( 'TooltipString' );
		end
		
		% Units
		function set.Units( this, val )
			this.set( 'Units', val );
		end
		function val = get.Units( this )
			val = this.get( 'Units' );
		end
		
		% Value
		function set.Value( this, val )
			this.set( 'Value', val );
		end
		function val = get.Value( this )
			val = this.get( 'Value' );
		end
		
		% BeingDeleted
		function set.BeingDeleted( this, val )
			this.set( 'BeingDeleted', val );
		end
		function val = get.BeingDeleted( this )
			val = this.get( 'BeingDeleted' );
		end
		
		% Children
		function set.Children( this, val )
			this.set( 'Children', val );
		end
		function val = get.Children( this )
			val = this.get( 'Children' );
		end
		
		% Clipping
		function set.Clipping( this, val )
			this.set( 'Clipping', val );
		end
		function val = get.Clipping( this )
			val = this.get( 'Clipping' );
		end
		
		% HandleVisibility
		function set.HandleVisibility( this, val )
			this.set( 'HandleVisibility', val );
		end
		function val = get.HandleVisibility( this )
			val = this.get( 'HandleVisibility' );
		end
		
		% HitTest
		function set.HitTest( this, val )
			this.set( 'HitTest', val );
		end
		function val = get.HitTest( this )
			val = this.get( 'HitTest' );
		end
		
		% Interruptible
		function set.Interruptible( this, val )
			this.set( 'Interruptible', val );
		end
		function val = get.Interruptible( this )
			val = this.get( 'Interruptible' );
		end
		
		% Parent
		function set.Parent( this, val )
			this.set( 'Parent', val );
		end
		function val = get.Parent( this )
			val = this.get( 'Parent' );
		end
		
		% Selected
		function set.Selected( this, val )
			this.set( 'Selected', val );
		end
		function val = get.Selected( this )
			val = this.get( 'Selected' );
		end
		
		% SelectionHighlight
		function set.SelectionHighlight( this, val )
			this.set( 'SelectionHighlight', val );
		end
		function val = get.SelectionHighlight( this )
			val = this.get( 'SelectionHighlight' );
		end
		
		% Tag
		function set.Tag( this, val )
			this.set( 'Tag', val );
		end
		function val = get.Tag( this )
			val = this.get( 'Tag' );
		end
		
		% Type
		function set.Type( this, val )
			this.set( 'Type', val );
		end
		function val = get.Type( this )
			val = this.get( 'Type' );
		end
		
		% UIContextMenu
		function set.UIContextMenu( this, val )
			this.set( 'UIContextMenu', val );
		end
		function val = get.UIContextMenu( this )
			val = this.get( 'UIContextMenu' );
		end
		
		% UserData
		function set.UserData( this, val )
			this.set( 'UserData', val );
		end
		function val = get.UserData( this )
			val = this.get( 'UserData' );
		end
		
		% Visible
		function set.Visible( this, val )
			this.set( 'Visible', val );
		end
		function val = get.Visible( this )
			val = this.get( 'Visible' );
		end
		
		
		% String2
		function set.String2( this, val )
			this.set( 'String2', val );
		end
		function val = get.String2( this )
			val = this.get( 'String2' );
		end
		
	end
	
	%% Events
	
	events
		ActionEvent
		KeyPressEvent
		ButtonDownEvent
		DeleteEvent
	end
	
	methods
		
		function Callback( this, EVENT )
			notify( this, 'ActionEvent', WrapperEvent( EVENT ) );
		end
		
		function KeyPressFcn( this, EVENT )
			notify( this, 'KeyPressEvent', WrapperEvent( EVENT ) );
		end
		
		function ButtonDownFcn( this, EVENT )
			notify( this, 'ButtonDownEvent', WrapperEvent( EVENT ) );
		end
		
		function DeleteFcn( this, EVENT )
			notify( this, 'DeleteEvent', WrapperEvent( EVENT ) );
			if isvalid( this )
				delete( this );
			end
		end
		
	end
	
	%% Constructor
	
	methods
		
		function this = ControlWrapper( varargin )
			
			this.createInternalHandle( ...
				varargin, ...
				'uicontrol', ...
				@(varargin)uicontrol( varargin{:} ), ...
				'Callback', @(HANDLE, EVENT) this.Callback( EVENT ), ...
				'KeyPressFcn', @(HANDLE, EVENT) this.KeyPressFcn( EVENT ), ...
				'ButtonDownFcn', @(HANDLE, EVENT) this.ButtonDownFcn( EVENT ), ...
				'DeleteFcn', @(HANDLE, EVENT) this.DeleteFcn( EVENT ) );
			
		end
		
	end
	
	%% External get
	
	methods
		
		function val = get( this, prop )
			if strcmp( prop, { 'String2' } )
				jh = this.jHandle;
				if isempty( jh )
					jh = findjobj( this.internalHandle );
					this.jHandle = jh;
				end
				val = char( jh.getText() );
			else
				val = get( this.internalHandle, prop );
			end
		end
		
	end
	
	%% Internal set
	
	methods( Access = protected )
		
		function finalSet( this, varargin )
			
			handle = this.internalHandle;
			props = reshape( varargin, 2, [] );
			
			for ii = find( strcmp( props(1,:), 'Parent' ) )
				props{2,ii} = double( props{2,ii} );
			end
			
			stringIdx = strcmp( props(1,:), 'String2' );
			if any( stringIdx )
				[ props{1,stringIdx} ] = deal( 'String' );
			end
			
			set( handle, props{:} );
			
		end
		
	end
	
end

Contact us