www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/+mbcgui/+dialog/StandardDialog.m
classdef StandardDialog < mbcgui.dialog.ObjectDialog %mbcgui.dialog.StandardDialog class % mbcgui.dialog.StandardDialog extends mbcgui.dialog.ObjectDialog. % % mbcgui.dialog.StandardDialog properties: % Parent - Property is of type 'MATLAB array' % Figure - Property is of type 'MATLAB array' (read only) % Title - Property is of type 'ustring' % Object - Property is of type 'MATLAB array' (read only) % HasObjectChanged - Property is of type 'bool' (read only) % HelpHandler - Property is of type 'string' % HelpCode - Property is of type 'string' % DisplayHelp - Property is of type 'bool' % UserData - Property is of type 'MATLAB array' % PageInfoFunction - Property is of type 'MATLAB array' % DisplaySinglePageAsTab - Property is of type 'bool' % % mbcgui.dialog.StandardDialog methods: % getDialogPanelSize - Return the desired size of the display panel % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (AbortSet,SetObservable) %PAGEINFOFUNCTION Property is of type 'MATLAB array' PageInfoFunction = []; %DISPLAYSINGLEPAGEASTAB Property is of type 'bool' DisplaySinglePageAsTab = false; end properties (Access=protected, AbortSet) %PAGEGROUP Property is of type 'handle' PageGroup = []; %SD_PROP_LISTENERS Property is of type 'handle vector' SD_Prop_Listeners = []; %SD_EVENT_LISTENERS Property is of type 'handle vector' SD_Event_Listeners = []; %SD_PANEL_LISTENERS Property is of type 'handle vector' SD_Panel_Listeners = []; end methods % constructor block function obj = StandardDialog(varargin) %STANDARDDIALOG Constructor for StandardDialog object % % OBJ = STANDARDDIALOG(EDITOBJECT, Prop, Value, ...) creates a new % StandardDialog object for editing or displaying the object EDITOBJECT. % Pages of information for the dialog are provided by the function handle % that is specified by the PageInfoFunction property. Property/value % pairs for additional properties can also be passed in. % Pass on other arguments to the superclass obj@mbcgui.dialog.ObjectDialog(varargin{ : }); % converted super class constructor call % Set up listeners that forward properties to the page group obj.SD_Prop_Listeners = [ ... event.proplistener(obj, obj.findprop('DisplaySinglePageAsTab'), ... 'PostSet', @(h,evt) obj.pSetPanel('DisplaySinglePageAsTab')); ... event.proplistener(obj, obj.findprop('PageInfoFunction'), ... 'PostSet', @(h,evt) obj.pSetPanel('PageInfoFunction')); ... ]; % Set up listeners that forward dialog events to the page group obj.SD_Event_Listeners = [ ... event.listener(obj, 'ObjectChanged', @pUpdatePanelObject); ... event.listener(obj, 'Finalize', @pFinalize); ... event.listener(obj, 'Cancel', @pCancel); ... ]; end % StandardDialog end % constructor block methods % public methods %---------------------------------------- function sz = getDialogPanelSize(obj) %GETDIALOGPANELSIZE Return the desired size of the display panel % SZ = GETDIALOGPANELSIZE(OBJ) returns a 2-element vector containing the % width and height of the dialog panel. This is taken as the maximum % values from all of the preferred widths and heights of the % DialogPageInfo objects. if ~isempty(obj.PageGroup) sz = obj.PageGroup.getPreferredSize; else sz = [380 400]; end end % getDialogPanelSize end % public methods methods (Access=protected) %---------------------------------------- function pAttachToPanel(obj, hPanel) %PATTACHTOPANEL Connect a new DialogPageGroup % PATTACHTOPANEL(OBJ, HPANEL) sets HPANEL as the new DialogPageGroup. obj.PageGroup = hPanel; % Set up help button obj.DisplayHelp = hPanel.hasAnyHelp; if obj.DisplayHelp obj.HelpHandler = hPanel.getCurrentHelpHandler; obj.HelpCode = hPanel.getCurrentHelpCode; end % Set up a listeners on the new PageGroup obj.SD_Panel_Listeners = [ ... event.listener(hPanel, 'PageChanged', @i_pagechange); ... event.listener(hPanel, 'ObjectChanged', @i_objectchange); ... ]; function i_pagechange(hPanel, ~) obj.HelpHandler = hPanel.getCurrentHelpHandler; obj.HelpCode = hPanel.getCurrentHelpCode; end function i_objectchange(hPanel, ~) obj.pEvents(false); obj.updateObject(hPanel.Object); obj.pEvents(true); end end %---------------------------------------- function pCancel(obj, ~) %PCANCEL Cancel the dialog % PCANCEL(OBJ, EVT) is called in response to the cancel event in the % dialog. The contained DialogPageGroup is cancelled. if ~isempty(obj.PageGroup) obj.PageGroup.cancel; obj.updateObject(obj.PageGroup.Object); end end % pCancel %---------------------------------------- function hPanel = pCreateDialogPanel(obj) %PCREATEDIALOGPANEL Create and return a display object % HPANEL = PCREATEDIALOGPANEL(OBJ) creates and returns a handle to an % object that is used as the gui for displaying and/or editing the % dialog's object. % Create a new DialogPageGroup hPanel = mbcgui.dialog.PageGroup('Parent', obj.Figure, ... 'PageInfoFunction', obj.PageInfoFunction, ... 'DisplaySinglePageAsTab', obj.DisplaySinglePageAsTab, ... 'Visible', 'off'); hPanel.updateObject(obj.Object); hPanel.initialize; obj.pAttachToPanel(hPanel); end % pCreateDialogPanel %---------------------------------------- function pEvents(obj, state) %PEVENTS Turn event listeners on or off % PEVENTS(OBJ, STATE) sets the enable state of the event listeners in the % object. [obj.SD_Event_Listeners.Enabled] = deal(state); end % pEvents %---------------------------------------- function pFinalize(obj, ~) %PFINALIZE Finalize the dialog % PFINALIZE(OBJ, EVT) is called in response to the finalize event in the % dialog. The contained DialogPageGroup is finalized. if ~isempty(obj.PageGroup) obj.PageGroup.finalize; obj.updateObject(obj.PageGroup.Object); end end % pFinalize %---------------------------------------- function pSetPanel(obj, prop) %PSETPANEL Set panel properties % PSETPANEL(OBJ, prop) sets properties on the contained DialogPageGroup in % response to a change in a property of this object. if ~isempty(obj.PageGroup) obj.PageGroup.(prop) = obj.(prop); end end % pSetPanel %---------------------------------------- function pUpdatePanelObject(obj, ~) %PUPDATEPANELOBJECT Update the panel's object % PUPDATEPANELOBJECT(OBJ, EVT) updates the panel's copy of the object and % ignores any events caused by this. obj.pEvents(false); obj.PageGroup.updateObject(obj.Object); obj.pEvents(true); end % pUpdatePanelObject end end % classdef