www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/+mbcgui/+actions/StatefulAction.m
classdef StatefulAction < mbcgui.actions.Action %mbcgui.actions.StatefulAction class % mbcgui.actions.StatefulAction extends mbcgui.actions.Action. % % mbcgui.actions.StatefulAction properties: % Command - Property is of type 'MATLAB callback' % Label - Property is of type 'string' % Description - Property is of type 'string' % IconFile - Property is of type 'string' % Visible - Property is of type 'bool' % Enabled - Property is of type 'bool' % % mbcgui.actions.StatefulAction methods: % execute - Perform the action command % setButtonProperties - Set button properties to match the action % setMenuProperties - Set menu item properties to match the action % setToolbuttonProperties - Set toolbar button properties to match the action % Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (SetObservable) %VISIBLE Property is of type 'bool' Visible = true; %ENABLED Property is of type 'bool' Enabled = true; end methods % constructor block function obj = StatefulAction(varargin) %STATEFULACTION Construct a new StatefulAction object % % OBJ = STATEFULACTION(COMMAND, LABEL, DESCRIPTION, ICONFILE) create a new % action that can have its visible and enable properties toggled. By % default the Enabled property is set up to fire StateChanged events. obj@mbcgui.actions.Action(varargin{ : }); % converted super class constructor call obj.enableStateChange({'Enabled'}); end % StatefulAction end % constructor block methods % public methods %---------------------------------------- function execute(obj) %EXECUTE Perform the action command % % EXECUTE(OBJ) evaluates the action's callback command. If the Action is % disabled, nothing will be executed. if obj.Enabled xregcallback(obj.Command, obj, []); end end % execute %---------------------------------------- function setButtonProperties(obj, hButton) %SETBUTTONPROPERTIES Set button properties to match the action % % SETBUTTONPROPERTIES(OBJ, HBUTTON) is called when the uicontrol button's % properties need to be set up to match the action's state. set(hButton, ... 'Enable', mbconoff(obj.Enabled), ... 'Visible', mbconoff(obj.Visible)); xregGui.iconuicontrol(hButton,'ImageFile',obj.IconFile,... 'TransparentColor',obj.TransparentColor); if isempty(hButton.CData) lbl = obj.pRemoveMnemonic(obj.Label); set(hButton,'String',lbl) else set(hButton,'TooltipString',obj.Description) end end % setButtonProperties %---------------------------------------- function setMenuProperties(obj, hMenu) %SETMENUPROPERTIES Set menu item properties to match the action % % SETMENUPROPERTIES(OBJ, HMENU) is called when the menu item's properties % need to be set up to match the action's state. hP = get(hMenu, 'Parent'); if ~isempty(hP) hCh = get(hP, 'Children'); hCh(hCh==hMenu) = []; OtherLabels = get(hCh, {'Label'}); lbl = obj.pUniqueMnemonic(obj.Label, OtherLabels); else lbl = obj.Label; end set(hMenu, ... 'Enable', mbconoff(obj.Enabled), ... 'Visible', mbconoff(obj.Visible), ... 'Checked', 'off', ... 'Label', lbl); end % setMenuProperties function setWorkflowProperties(obj,wf) setWorkflowProperties@mbcgui.actions.Action(obj,wf) set(wf,'Enable',mbconoff(obj.Enabled)) end %---------------------------------------- function setToolbuttonProperties(obj, hButton) %SETTOOLBUTTONPROPERTIES Set toolbar button properties to match the action % % SETTOOLBUTTONPROPERTIES(OBJ, HBUTTON) is called when the menu item's % properties need to be set up to match the action's state. set(hButton, ... 'Enable', mbconoff(obj.Enabled), ... 'Visible', mbconoff(obj.Visible), ... 'ImageFile', obj.IconFile, ... 'TransparentColor',obj.TransparentColor,... 'TooltipString', obj.Description); end % setToolbuttonProperties end % public methods end % classdef