www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/mbcWorkflowItem.m
classdef mbcWorkflowItem < mbcgui.widget.BasicContainer %mbcWorkflowItem workflow item consisting of a button and some text % Copyright 2015-2016 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (Dependent) %IconFile full icon file IconFile %Label label for workflow item Label %Separator place a separator before the item Separator = 'off'; %Interruptible Interruptible end properties %Callback callback for button and text ButtonDownFcn Callback %TransparentColor transparency color TransparentColor = [255 0 255]; %WorkflowPanel WorkflowPanel end properties (Dependent,GetAccess=private) Action end properties (Access=private) %hText text item hText %hButton button hButton %pLabel private store for label text pLabel %pIconFile private store for icon file pIconFile %pSeparator private store for separator pSeparator = 'off'; end methods function obj = mbcWorkflowItem(varargin) %mbcWorkflowItem constructor obj@mbcgui.widget.BasicContainer(varargin{:}); col = mbcgui.util.SystemColorsDbl.COMMONTASKS; FontSize = 10; if ~isempty(obj.IconFile) obj.hButton = xregGui.iconuicontrol('Parent', obj.Parent,... 'ImageFile', obj.IconFile,... 'TransparentColor',obj.TransparentColor,... 'Callback', @obj.callbackHandler); else obj.hButton = xregGui.iconuicontrol('Parent', obj.Parent,... 'Callback', @obj.callbackHandler); end obj.hText = uicontrol('Parent',obj.Parent,... 'Style','text',... 'HorizontalAlignment','left',... 'FontSize',FontSize,... 'BackgroundColor',col,... 'ButtonDownFcn',@obj.callbackHandler,... 'String',obj.Label,... 'Enable','inactive'); obj.ContentHandle = xreggridbaglayout(obj.Parent,... 'dimension',[2,2],... 'elements',{obj.hButton,[],[],obj.hText},... 'gapx',2,... 'RowSizes',[3 -1],... 'ColSizes',[25 -1],... 'MergeBlock',{[1 2],[1 1]}); end function set.IconFile(obj,icon) if isgraphics(obj.hButton,'uicontrol') %update button icon xregGui.iconuicontrol(obj.hButton,'ImageFile',icon,... 'TransparentColor',obj.TransparentColor); end obj.pIconFile = icon; end function set.Action(obj,action) obj.IconFile = action.IconFile; obj.Label = action.Label; obj.Callback = action.Command; end function set.Separator(obj,sep) obj.pSeparator = sep; if ~isempty(obj.WorkflowPanel) && strcmpi(sep,'on') % add separator to workflow panel. This will not work until the % WorkflowPanel has been constructed pos = find(obj == obj.WorkflowPanel.Items); addSeparator(obj.WorkflowPanel,pos); end end function sep = get.Separator(obj) sep = obj.pSeparator; end function ic = get.IconFile(obj) ic = obj.pIconFile; end function set.Label(obj,label) if isgraphics(obj.hText) set(obj.hText,'String',label) end obj.pLabel = label; end function label =get.Label(obj) label = obj.pLabel; end function st = get.Interruptible(obj) st = obj.hButton.Interruptible; end function set.Interruptible(obj,st) %set.Interruptible set Interruptible for button and text obj.hButton.Interruptible = st; obj.hText.Interruptible = st; end end methods (Access=protected) function setEnable(obj,en) if strcmpi(en,'off') set(obj.hText,'Enable','off') else % text needs to be inactive for the button down function to % work set(obj.hText,'Enable','inactive') end set(obj.hButton,'Enable',en) end end methods (Access=private) function callbackHandler(obj,h,evt) % set pointer to a watch before calling the Callback hFig = ancestor(obj.hButton,'figure'); Pointer = get(hFig,'Pointer'); set(hFig,'Pointer','watch') drawnow update % main callback xregcallback(obj.Callback,h,evt); set(hFig,'Pointer',Pointer) end end end