www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregGui/@dialog/pCreateButtons.m
function buttons = pCreateButtons(obj) %PCREATEBUTTONS Private method to create the Buttons. % % BUTTONS = PCREATEBUTTONS(OBJ) Creates the buttons specified but the % Buttons property and returns a cell array of button handles in the % order they should be laid out (left to right). Also sets the dialog % CloseAction, again based on the Buttons property. % Copyright 2007 The MathWorks, Inc. % Here we translate the 'enumerated' Buttons [property to the names of the % actions we need buttons for. The order of the names is the order the % buttons will be in. switch obj.Buttons case 'OK_CANCEL_HELP' actionNames = {'OK', 'CANCEL', 'HELP'}; obj.CloseAction = 'CANCEL'; defaultAction = 'OK'; case 'OK_CANCEL' actionNames = {'OK', 'CANCEL'}; obj.CloseAction = 'CANCEL'; defaultAction = 'OK'; case 'OK_HELP' actionNames = {'OK', 'HELP'}; obj.CloseAction = 'OK'; defaultAction = 'OK'; case 'CANCEL_HELP' actionNames = {'CANCEL', 'HELP'}; obj.CloseAction = 'CANCEL'; defaultAction = 'CANCEL'; case 'CANCEL' actionNames = {'CANCEL'}; obj.CloseAction = 'CANCEL'; defaultAction = 'CANCEL'; case 'CLOSE' actionNames = {'CLOSE'}; obj.CloseAction = 'CLOSE'; defaultAction = 'CLOSE'; case 'OK' actionNames = {'OK'}; obj.CloseAction = 'OK'; defaultAction = 'OK'; otherwise % We should never get here - the check on the property set should % have errored if the value is invalid. error(message('mbc:xregGui:dialog:InvalidOption', obj.Buttons)); end % If no DefaultAction has been specified use the calculated default. if isempty( obj.DefaultAction ) obj.DefaultAction = defaultAction; else % check the user provided DefaultAction is one of the actions we have a % button for. if ~ismember( obj.DefaultAction, actionNames ) error(message('mbc:xregGui:dialog:InvalidProperty', obj.DefaultAction, obj.Buttons)); end end numButtons = length(actionNames); buttons = cell(1, numButtons); for i=1:numButtons name = actionNames{i}; buttons{i} = obj.Actions.(name).createButton( obj.Figure ); obj.ButtonHandles.(name) = buttons{i}; end